Skip to content

Commit

Permalink
Dont fail all scenarios if Harmony patching fails (#437)
Browse files Browse the repository at this point in the history
Closes #436
  • Loading branch information
delatrie authored Nov 28, 2023
1 parent 51b6f15 commit 1b48e19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 12 additions & 1 deletion Allure.SpecFlowPlugin/AllureBindingInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Specialized;
using System.IO;
using Allure.Net.Commons;
using Allure.SpecFlowPlugin.SelectiveRun;
using TechTalk.SpecFlow;
Expand Down Expand Up @@ -43,7 +44,8 @@ IUnitTestRuntimeProvider unitTestRuntimeProvider
{
this.testRunnerManager = testRunnerManager;
AllureSpecFlowPatcher.EnsureTestPlanSupportInjected(
unitTestRuntimeProvider
unitTestRuntimeProvider,
WriteErrorToFileSafe
);
}

Expand Down Expand Up @@ -75,6 +77,15 @@ out duration
);
}

static void WriteErrorToFileSafe(Exception e)
{
try
{
File.WriteAllText(".allure_patch_error", e.ToString());
}
catch (Exception) { }
}

(object, TimeSpan) ProcessHook(
IBinding binding,
IContextManager contextManager,
Expand Down
13 changes: 11 additions & 2 deletions Allure.SpecFlowPlugin/SelectiveRun/AllureSpecFlowPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -13,15 +14,23 @@ static class AllureSpecFlowPatcher
static bool isTestPlanSupportInjected= false;

internal static void EnsureTestPlanSupportInjected(
IUnitTestRuntimeProvider unitTestRuntimeProvider
IUnitTestRuntimeProvider unitTestRuntimeProvider,
Action<Exception> logError
)
{
if (isTestPlanSupportInjected)
{
return;
}

InjectTestPlanSupport(unitTestRuntimeProvider);
try
{
InjectTestPlanSupport(unitTestRuntimeProvider);
}
catch (Exception e)
{
logError(e);
}
isTestPlanSupportInjected = true;
}

Expand Down

0 comments on commit 1b48e19

Please sign in to comment.