Skip to content

loopguard: read python's own options before a test run - #226

Open
Lanre Shittu (Shizoqua) wants to merge 1 commit into
microsoft:mainfrom
Shizoqua:fix-loopguard-python-options
Open

Lanre Shittu (Shizoqua) wants to merge 1 commit into
microsoft:mainfrom
Shizoqua:fix-loopguard-python-options

Conversation

@Shizoqua

Copy link
Copy Markdown

python -W error -m pytest, python -X dev -m pytest and python -u -m unittest put the interpreter's options between python and -m. VERIFY_RE read only python -m, so the run was not a verification, and a failing run after the last edit left the turn counted as ended green. python -W error manage.py test and python -u tests/runtests.py had the same gap.

Fix: Python's flags (-b, -B, -d, -E, -i, -I, -O, -P, -q, -s, -S, -u, -v, -x, and -W/-X with their value, attached or not) are passed over before what it runs, case-sensitively, as the ruby options are. python -W error repro.py, python -X dev -c '...' and python -u -m pip install -e . are still not test runs.

Tests, in tests/test_live_core.py next to the env/nice ones:

  • test_a_runner_behind_pythons_own_options_counts_as_a_verification: 10 commands. Each is a verification, and a failing run after an edit is not ended green. All 10 fail on main (assert None == 'own') and pass with the fix.
  • test_pythons_own_options_leave_what_it_runs_to_decide: 4 commands that stay non-runs.
python -m pytest tests -rfEs --tb=line
1014 passed, 17 skipped

The skips need a real Codex, Hermes, opencode or aider, Windows, or a non-root user.

Fixes #224

`python -W error -m pytest`, `python -X dev -m pytest` and `python -u -m unittest` put the
interpreter's options between `python` and `-m`. The verification pattern read only `python -m`,
so the run was not a verification, and a failing run after the last edit left the turn counted
as ended green. The same held for `python -W error manage.py test` and
`python -u tests/runtests.py`.

Python's flags (`-b`, `-B`, `-E`, `-I`, `-O`, `-u`, ... and `-W`/`-X` with their value) are now
passed over, case-sensitively, before what it runs. `python -W error repro.py` and
`python -u -m pip install` are still not test runs.

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.

Looks correct. Here's what I checked.

  • _PYTHON is used in both places the pattern names the interpreter. That's the optional launcher prefix (turn.py:42, which covers python -u tests/runtests.py and python -W error manage.py test) and the python -m pytest|unittest alternative (:43). status_of_tests only matches VERIFY_RE at the start of each stage after _PREFIX_RE (:166), so uv run python -X dev -m pytest and PYTHONWARNINGS=error python -W error -m pytest work as well.
  • The scoped (?-i:...) keeps the flags case-sensitive under the outer (?i), the same way the ruby options do. -m and -c aren't in the flag class. So python -u -m pip install pytest and python -W error -c "import pytest" stay non-runs: the match is anchored, so the later pytest is never reached.
  • I ran the pattern on edge cases beyond the new tests. -Wd, -W ignore::DeprecationWarning -m unittest, -OO, -X importtime, -X utf8=1, -s -E and -x -m pytest all give own. python -E repro.py gives None. A -W/-X value can't start with -, so -W can't take the next flag as its value.
  • No backtracking risk. Each repeated option starts with \s+- and its value \S* can't cross whitespace, so the * group can only split one way.
  • I ran tests/test_live_core.py and tests/test_cache_write_1h.py on the branch: 287 passed, 1 skipped. git merge-tree against main is clean.

Out of scope, as the comment above VERIFY_RE says: state.TEST_RUN_RE (state.py:17-19) still only knows python -m unittest. So python -u -m unittest adds to verifications, but not to SpiralState.test_runs (state.py:195). python -W error -m pytest is counted there anyway, through \bpytest\b.

Reviewed with help from Claude Code.

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.

loopguard: python -W error -m pytest is not counted as a test run

2 participants