Fix CLI options ignored when --looponfail runs with -n (#767)#1340
Fix CLI options ignored when --looponfail runs with -n (#767)#1340golikovichev 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 needs a deep reviews - ithis trops on the incorrect config restore, but i take note that this only fixes part of the issue - im at the pytest sprint and will experiment with a more nuanced approach |
|
Thanks for looking, and no rush - enjoy the sprint. You're right that it's partial. It targets the specific #767 case where If your read is that the restore is papering over an incorrect |
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.