Skip to content

Commit 1fac6f8

Browse files
committed
#2377: Test logs get mixed across test cases
1 parent e022e5c commit 1fac6f8

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/xunit.execution/Sdk/Frameworks/Runners/XunitTestClassRunner.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ protected override bool TryGetConstructorArgument(ConstructorInfo constructor, i
225225
{
226226
if (parameter.ParameterType == typeof(ITestOutputHelper))
227227
{
228-
argumentValue = new TestOutputHelper();
228+
// To solve https://github.com/xunit/xunit/issues/2377 we're putting a placeholder Func here,
229+
// and hardcoding the resolution of that in XunitTestRunner.cs. In v3, we generally support
230+
// using Funcs, because we resolve this via the TestContext (so it's already fixed there).
231+
argumentValue = () => new TestOutputHelper();
229232
return true;
230233
}
231234

src/xunit.execution/Sdk/Frameworks/Runners/XunitTestRunner.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ protected override async Task<Tuple<decimal, string>> InvokeTestAsync(ExceptionA
5454
var output = string.Empty;
5555

5656
TestOutputHelper testOutputHelper = null;
57-
foreach (object obj in ConstructorArguments)
58-
{
59-
testOutputHelper = obj as TestOutputHelper;
60-
if (testOutputHelper != null)
57+
for (int idx = 0; idx < ConstructorArguments.Length; ++idx)
58+
if (ConstructorArguments[idx] is Func<TestOutputHelper>)
59+
{
60+
testOutputHelper = new TestOutputHelper();
61+
ConstructorArguments[idx] = testOutputHelper;
6162
break;
62-
}
63+
}
6364

6465
if (testOutputHelper != null)
6566
testOutputHelper.Initialize(MessageBus, Test);

0 commit comments

Comments
 (0)