<PackageReference Include="NUnit" Version="3.0.0-beta-4" />

ApplyChangesToContextCommand

ContextSettingsCommand applies specified changes to the TestExecutionContext prior to running a test. No special action is needed after the test runs, since the prior context will be restored automatically.
using NUnit.Framework.Interfaces; using System; using System.Threading; namespace NUnit.Framework.Internal.Commands { internal class ApplyChangesToContextCommand : DelegatingTestCommand { private IApplyToContext[] _changes; public ApplyChangesToContextCommand(TestCommand innerCommand, IApplyToContext[] changes) : base(innerCommand) { _changes = changes; } public override TestResult Execute(TestExecutionContext context) { try { IApplyToContext[] changes = _changes; for (int i = 0; i < changes.Length; i++) { changes[i].ApplyToContext(context); } context.CurrentResult = innerCommand.Execute(context); } catch (Exception ex) { if (ex is ThreadAbortException) Thread.ResetAbort(); context.CurrentResult.RecordException(ex); } return context.CurrentResult; } } }