Fix CLI options ignored when --looponfail runs with -n (#767)#1340
Open
golikovichev wants to merge 2 commits into
Open
Fix CLI options ignored when --looponfail runs with -n (#767)#1340golikovichev wants to merge 2 commits into
golikovichev wants to merge 2 commits into
Conversation
When --looponfail runs the failing tests through distributed (-n) workers, the worker session config was rebuilt only from the parsed options and the positional arguments, so config.invocation_params.args lost the original command-line flags such as --tb=short. xdist reads invocation_params.args to replicate options on its workers, so the nested workers fell back to their defaults (for example, the long traceback style). Restore the full invocation arguments in the looponfail worker config so those options propagate to the nested workers. Closes pytest-dev#767
dataclasses.replace() raises TypeError on pytest 7.x, where InvocationParams is a frozen attrs class rather than a dataclass. Build the replacement through the type's own constructor instead, which works for both the attrs (7.x) and dataclass (newer pytest) variants.
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.
Fixes #767.
Problem
pytest --tb=short -n2 --looponfailignores--tb=shortand prints a long traceback. The option is only dropped when--looponfailand-nare combined; each on its own respects--tb=short.Root cause
--looponfailrebuilds the worker session config viaConfig.fromdictargs(option_dict, args), whereargsis the positional test paths only.fromdictargssetsconfig.invocation_params.argsto exactly those positional arguments, so the original command-line flags (e.g.--tb=short) are not present there, even thoughconfig.optioncarries them.That is fine for looponfail's own in-process run, which reads
config.optiondirectly. But when looponfail runs a nested distributed (-n) session,WorkerController.setupbuilds the nested worker argv fromconfig.invocation_params.args(workermanage.py). Since the flags are missing there, the nested workers fall back to their defaults, including the long traceback style.Fix
Pass the original invocation arguments to the looponfail worker and restore a faithful
config.invocation_params.argsafterfromdictargs. This propagates all command-line flags (not just--tb) to nested workers.dataclasses.replaceis used becauseInvocationParamsis a frozen dataclass;pluginsanddirare preserved.Tests
Added a regression test in
testing/test_looponfail.pythat runs the failing tests throughRemoteControl.loop_once()with-n2 --tb=shortand asserts the short-style traceback markers appear (and the long-style source expansion does not).Verified locally:
testing/test_looponfail.pypasses (no regressions).ruff check,ruff format --check, andmypyare clean.