fix: keep the log handler set by the brokerage test project - #9640
Merged
Martin-Molinero merged 1 commit intoJul 28, 2026
Merged
Conversation
- stop replacing it with NUnitLogHandler on every test - brokerage test projects keep their file log for the whole run
Romazes
force-pushed
the
feature-keep-brokerage-test-log-handler
branch
from
July 27, 2026 19:44
b5147f6 to
a2705df
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
BrokerageTests.SetupreplacedLog.LogHandlerwith a newNUnitLogHandlerbefore every test. That line is removed, so the log handler chosen by the test project is kept.Related Issue
N/A
Motivation and Context
No fixture in Lean derives from
BrokerageTests. Its consumers are the brokerage plugin repositories (Lean.Brokerages.Tastytrade,Lean.Brokerages.CharlesSchwab,Lean.Brokerages.Alpacaand others), which use it as the base class for their live brokerage tests. Each of them sets a log handler in its ownTestSetup:That line runs once, from a
TestCaseSourcewhile NUnit builds the test tree, and never runs again. The first brokerage test replaced it, so for the rest of the run there was nolog.txtand no console output. The only place left wasTestContext.Progress, which the defaultdotnet testconsole logger does not print. A failing brokerage test in CI showed no log at all.Why
ConsoleLogHandleris the better default hereBoth handlers write the same text. They differ in where the text goes and who can read it there.
dotnet test)Errorgoes to stderr, the rest to stdout, so error lines can move2> errors.txtThe order difference is real but small. Three logged lines:
With
ConsoleLogHandlerthe error line travels on a different stream, so it can arrive last and look like the socket broke first.NUnitLogHandlerkeeps the order.The CI difference is the one that costs something. With
NUnitLogHandleronly, a failing test in GitHub Actions produces an empty log.NUnitLogHandleris tidier,ConsoleLogHandlerreaches more places, and the test project is the right place to make that choice.Consumers that set no handler keep Lean's default
ConsoleLogHandlerinstead of getting anNUnitLogHandler. Their output is still shown in Visual Studio while the test runs, and now it is also shown in CI when a test fails.Requires Documentation Change
No
How Has This Been Tested?
dotnet testconsole logger printsConsole.Outfor a failing test, but never printsTestContext.Progress. This is why the handler fromTestSetuphas to survive.TestSetupin the brokerage plugin repositories sets the log handler once, before any[SetUp]runs.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>