From 2a56a3749cb55e7c7347d1e54006a78dcf7cda08 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Tue, 28 Nov 2023 00:44:42 +0700 Subject: [PATCH] Dont fail all scenarios if Harmony patching fails Closes #436 --- Allure.SpecFlowPlugin/AllureBindingInvoker.cs | 13 ++++++++++++- .../SelectiveRun/AllureSpecFlowPatcher.cs | 13 +++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Allure.SpecFlowPlugin/AllureBindingInvoker.cs b/Allure.SpecFlowPlugin/AllureBindingInvoker.cs index 49c3a80f..635c4ef4 100644 --- a/Allure.SpecFlowPlugin/AllureBindingInvoker.cs +++ b/Allure.SpecFlowPlugin/AllureBindingInvoker.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Specialized; +using System.IO; using Allure.Net.Commons; using Allure.SpecFlowPlugin.SelectiveRun; using TechTalk.SpecFlow; @@ -43,7 +44,8 @@ IUnitTestRuntimeProvider unitTestRuntimeProvider { this.testRunnerManager = testRunnerManager; AllureSpecFlowPatcher.EnsureTestPlanSupportInjected( - unitTestRuntimeProvider + unitTestRuntimeProvider, + WriteErrorToFileSafe ); } @@ -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, diff --git a/Allure.SpecFlowPlugin/SelectiveRun/AllureSpecFlowPatcher.cs b/Allure.SpecFlowPlugin/SelectiveRun/AllureSpecFlowPatcher.cs index 098ead92..507729d4 100644 --- a/Allure.SpecFlowPlugin/SelectiveRun/AllureSpecFlowPatcher.cs +++ b/Allure.SpecFlowPlugin/SelectiveRun/AllureSpecFlowPatcher.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -13,7 +14,8 @@ static class AllureSpecFlowPatcher static bool isTestPlanSupportInjected= false; internal static void EnsureTestPlanSupportInjected( - IUnitTestRuntimeProvider unitTestRuntimeProvider + IUnitTestRuntimeProvider unitTestRuntimeProvider, + Action logError ) { if (isTestPlanSupportInjected) @@ -21,7 +23,14 @@ IUnitTestRuntimeProvider unitTestRuntimeProvider return; } - InjectTestPlanSupport(unitTestRuntimeProvider); + try + { + InjectTestPlanSupport(unitTestRuntimeProvider); + } + catch (Exception e) + { + logError(e); + } isTestPlanSupportInjected = true; }