Skip to content

Make script and OIDC logout tests robust to serial (-n0) execution#3507

Merged
jonathangreen merged 1 commit into
mainfrom
chore/fix-tests-serial-execution
Jun 26, 2026
Merged

Make script and OIDC logout tests robust to serial (-n0) execution#3507
jonathangreen merged 1 commit into
mainfrom
chore/fix-tests-serial-execution

Conversation

@jonathangreen

Copy link
Copy Markdown
Member

Description

Makes four tests robust to running serially with pytest-xdist disabled (-n0). They pass under the normal xdist test run but fail under -n0, which is how the backwards-compatibility CI check (#3506) runs a previous release's database suite against the current schema.

  • Three script tests (test_equivalents, test_novelist, test_search) constructed a Script with no cmd_args and called do_run(), so the script's argparse fell back to sys.argv[1:]. Under xdist each worker has a clean execnet sys.argv, but under -n0 sys.argv is the real pytest command line. That caused argparse to error on unrecognized arguments (equivalents, novelist), and the leaked -m db marker matched RebuildSearchIndexScript's -m/--migration flag, sending it down the migration path so search_reindex.delay was never called (search). Each now passes an explicit cmd_args=[] to express "no arguments" independent of sys.argv.
  • The OIDC logout test (test_oidc_logout_initiate_no_stored_id_token) asserted on caplog without setting a capture level. Under serial execution the effective log level is left raised by an earlier test, so the warning was not captured and caplog.text was empty. It now sets the level explicitly, matching its passing sibling test_oidc_logout_initiate_revocation_only.

No production code changes — scripts intentionally default cmd_args to sys.argv for real CLI use via Script.run().

Motivation and Context

The backwards-compatibility check added in #3506 runs the previous release's -m db suite under -n0 (external-schema mode requires serial execution — the single shared database can't be used by parallel xdist workers). Its first real run surfaced these four latent test-isolation bugs, which xdist had been masking. None are schema-compatibility failures; all four fail identically against the previous release's own schema. Fixing them here means that once a release containing these fixes becomes the "previous release", the check will pass against it.

How Has This Been Tested?

Reproduced the failures on the unfixed tests by running them under -n0 in the docker test environment (tox -e py312-docker -- -n0 ...), observing the argparse unrecognized arguments errors. With the fixes applied, all four pass under -n0 (including with -m db present, which exercises the search flag-collision case): 60 passed, 19 deselected.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

These tests pass under the normal xdist test run but fail when the suite
runs serially with pytest-xdist disabled (-n0), which is how the
backwards-compatibility CI check exercises a previous release's suite.

The three script tests constructed a Script with no cmd_args and called
do_run(), so the script's argparse fell back to sys.argv[1:]. Under xdist
each worker has a clean execnet argv, but under -n0 sys.argv is the real
pytest command line, so argparse either errored on unrecognized arguments
(equivalents, novelist) or silently matched a flag -- the leaked '-m db'
marker tripped RebuildSearchIndexScript's -m/--migration flag, sending it
down the migration path so search_reindex.delay was never called. Pass an
explicit cmd_args=[] to express 'no arguments' independent of sys.argv.

The OIDC logout test asserted on caplog without setting a capture level.
Under serial execution the effective log level is left raised by an
earlier test, so the warning was not captured. Set the level explicitly,
matching the sibling test_oidc_logout_initiate_revocation_only.
@jonathangreen jonathangreen requested a review from a team June 25, 2026 17:36
@claude

claude Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Claude finished @jonathangreen's task in 1m 28s —— View job


Review

  • Read the changed files and surrounding context
  • Understand Script / cmd_args handling (constructor vs do_run)
  • Verify the OIDC caplog change
  • Post review

Summary

This is a clean, well-scoped test-isolation fix and the PR description accurately diagnoses each failure. I traced all four changes against the code under test and they are each correct and placed at the right call site. No production code is touched, and the asymmetry in where cmd_args=[] is passed is justified by where each script actually parses its arguments — there's nothing to change. No blocking issues found.

For the record, the three script call sites line up with the parsing location in each script:

  • EquivalentIdentifiersRefreshScript.do_run() parses cmd_args itself (scripts/equivalents.py:44), so do_run(cmd_args=[]) is right.
  • NovelistSnapshotScript.do_run() forwards **kwargs into parse_command_line (scripts/novelist.py:13-14), so do_run(cmd_args=[]) reaches parse_args([]) correctly.
  • RebuildSearchIndexScript parses in __init__ (scripts/search.py:23) and its do_run() takes no args, so cmd_args=[] must go to the constructor.

And the OIDC change is sound: the message is logged at WARNING (oidc/controller.py:492), so caplog.set_level(logging.INFO) captures it, consistent with the passing sibling test_oidc_logout_initiate_revocation_only (test_controller.py:888).
chore/fix-tests-serial-execution

@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes four test-isolation bugs that were masked by pytest-xdist parallel execution and surfaced when tests are run serially (-n0) as needed by the backwards-compatibility CI check from #3506. No production code is changed.

  • Three script tests (test_equivalents, test_novelist, test_search) now pass cmd_args=[] to prevent argparse from falling back to sys.argv[1:] and picking up pytest's own arguments in serial mode.
  • The OIDC logout test now explicitly sets caplog.set_level(logging.INFO) to avoid capturing being suppressed by a raised log level left over from a previously-run test.

Confidence Score: 5/5

All changes are confined to test files; no production behaviour is altered.

Each change is a single-line, targeted isolation fix. The script tests now explicitly pass cmd_args=[] so they no longer depend on sys.argv, and the OIDC test now owns its capture level rather than inheriting whatever a previous test left behind. All four fixes are consistent with the patterns already established in neighbouring tests in the same files.

No files require special attention.

Important Files Changed

Filename Overview
tests/manager/scripts/test_equivalents.py Passes cmd_args=[] to do_run() to prevent argparse from reading sys.argv under serial execution; fix is correct and consistent with the other script tests.
tests/manager/scripts/test_novelist.py Passes cmd_args=[] to do_run() to isolate test from sys.argv; matches the fix pattern applied in test_equivalents.py.
tests/manager/scripts/test_search.py Passes cmd_args=[] to the constructor (not do_run) because RebuildSearchIndexScript parses args at construction time; all other tests in this file already used explicit cmd_args, so this brings the no-args test into consistency.
tests/manager/integration/patron_auth/oidc/test_controller.py Adds caplog.set_level(logging.INFO) to test_oidc_logout_initiate_no_stored_id_token, matching the already-passing sibling test to prevent log-level leakage from earlier tests.

Reviews (1): Last reviewed commit: "Make script and OIDC logout tests robust..." | Re-trigger Greptile

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.44%. Comparing base (2a04c63) to head (c6092e0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3507   +/-   ##
=======================================
  Coverage   93.44%   93.44%           
=======================================
  Files         511      511           
  Lines       46465    46465           
  Branches     6339     6339           
=======================================
+ Hits        43419    43421    +2     
+ Misses       1969     1968    -1     
+ Partials     1077     1076    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tdilauro tdilauro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧

@jonathangreen jonathangreen merged commit ff3405d into main Jun 26, 2026
23 checks passed
@jonathangreen jonathangreen deleted the chore/fix-tests-serial-execution branch June 26, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants