TR-20810: References are added incorrectly after closing test runs - #456
TR-20810: References are added incorrectly after closing test runs#456acuanico-tr-galt wants to merge 12 commits into
Conversation
…ty scanning in tox script
…st, add, delete and update support for TestRail enterprise
…s this was already handled in tox.ini during pip audit
… in payload even for dataset name changes only
…haracters that may confuse Clicks text wrapper
…, also added unit tests and updated README guide
…interference and multisuite close-run regression
| # Normal mode: process each suite separately | ||
| # Defer close_run if test_run_ref is provided to attach references first | ||
| defer_close = environment.test_run_ref is not None | ||
| run_ids = [] # Track all run IDs created/used |
There was a problem hiding this comment.
run_ids is scoped inside the else: branch but read outside it → crash in multisuite mode
When special_parser == "multisuite" the if branch at line 100 runs and line 112 never executes, so line 130 dereferences an unbound local. The old code was safe because it used run_id, which is initialised to None at line 96 before the branch.
There was a problem hiding this comment.
We've now Hoisted run_ids = [] to line 97 (top-level scope) so no more crashes in multisuite mode.
| @@ -107,19 +107,35 @@ def cli(environment: Environment, context: click.Context, *args, **kwargs): | |||
| run_id = multisuite_uploader.last_plan_id | |||
There was a problem hiding this comment.
run_id is now written at lines 96, 107 and 122–123 and never read again. I checked every occurrence in the file — after line 123 only run_ids / current_run_id are used.
So even once the scope bug is fixed by hoisting run_ids = [], multisuite mode would take the if environment.test_run_ref and run_ids: branch with an empty list and silently skip reference attachment entirely. Before this commit, _handle_test_run_references(environment, run_id) did attach refs to the plan ID. That behaviour is lost.
The # Keep first run_id for backward compatibility comment at line 121 is misleading — nothing consumes it. Either feed the multisuite plan ID into run_ids (run_ids = [multisuite_uploader.last_plan_id]) or drop run_id and handle the multisuite branch explicitly. Worth deciding deliberately, since it also settles the "does --close-run apply to multisuite plans?" question I raised earlier.
There was a problem hiding this comment.
FIxed to populate run_ids = [plan_id] in multisuite branch
| # Handle test run references and closing for all runs | ||
| if environment.test_run_ref and run_ids: | ||
| # Attach references to all runs | ||
| for current_run_id in run_ids: |
There was a problem hiding this comment.
_handle_test_run_references ends with its own print(json.dumps(result, indent=2)) under if environment.json_output: (line 226). Looping it over N runs concatenates N standalone top-level JSON objects, which jq and json.loads both reject.
Slightly ironic given this same commit fixes JSON purity in the datasets/variables commands. If multi-run JSON output matters, accumulate the per-run results and emit one array after the loop.
There was a problem hiding this comment.
Fixed this by accumulating results into array, print single valid JSON.
Solution description
There is an issue where references are not correctly appended to runs when using --close-run option with --test-run-ref.
Changes
Defer the close_run operation when --test-run-ref is present, allowing references to be attached first.
Potential impacts
None
Steps to test
Parse a sample junit file and use --test-run-ref and --close-run together. There should be no error and references are added to the run correctly.
PR Tasks