Skip to content

tests/test_amd_swizzle: run the whole file when it is run directly - #4951

Closed
bobcatchris wants to merge 0 commit into
ItsNotRexed:mainfrom
bobcatchris:cont/test-late-defs
Closed

bobcatchris wants to merge 0 commit into
ItsNotRexed:mainfrom
bobcatchris:cont/test-late-defs

Conversation

@bobcatchris

@bobcatchris bobcatchris commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claim: #4816 (comment) (direct execution skipped the tests below the __main__ block; CI already routes this file to pytest)

What broke. tests/test_amd_swizzle.py carried its __main__ block at line 61, driving a hand-rolled globals() loop. Run directly as a script, it printed two ok lines from the tests defined above the loop and exited 0; the rest were silently skipped (pytest collects 10). Several of the skipped ones take the tmp_path fixture, which the loop could never have supplied anyway: fn() raises TypeError: missing 1 required positional argument, so the loop was not merely stale, it was structurally unable to run the file's fixture tests. CI was not affected: the ^import pytest marker keeps this file out of the python -I stdlib loop (ci.yml:17, ci.yml:83), and the pytest leg already ran it (ci.yml:147-153). This was a local direct-run bug only.

Fix. Move the guard to the end of the file and delegate to pytest.main([__file__]). The module already imports pytest unconditionally at the top (with a numpy-absent skip path), so direct execution carries the same requirement as importing it. Discovery and pytest runs are unchanged; python -m unittest-style collection is not used by this file.

Scope note. Of the five files my sweep originally found, the merge round fixed tests/semantic/test_salu_pack_b32.py and tests/semantic/test_lds_atomic_inc_u32.py mid-flight (commit 023a7f6c4 and the guard's removal), and tests/test_rpf9_carve.py + tests/test_shader_checks.py are #3236's open scope — this PR deliberately touches neither. tests/test_amd_swizzle.py is the one left; #4818/#3355 also edit it (tool-side validation) — textual adjacency only, both add tests near the tail which will now sit above the moved guard and run in CI too. Depends on: #4818, #3355 (adjacency, not logic).

Verified (Windows, Python 3.12, CPU only, no game data):

  • python -m pytest tests/test_amd_swizzle.py — 10 passed (after installing the repo's own pinned Pillow from tests/requirements.txt; three of the seven newly reachable tests are preview tests that need it — they were unrunnable on boxes without Pillow, which is part of why the skip went unnoticed).
  • python tests/test_amd_swizzle.py — 10 passed via the new pytest.main runner; previously two ok lines and exit 0.
  • python -m compileall -q tests/test_amd_swizzle.py — clean.
  • No behavioural change under pytest/discovery; no tool code touched.

AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

APPROVE - the fix is right, but the body's premise is wrong.

Direct execution now runs the whole file: 7 passed / 3 skipped (PIL absent), exit 0, and pytest on the same file matches. raise SystemExit(pytest.main(...)) propagates the status correctly (tests/test_amd_swizzle.py:218-223); on main the direct run prints only two ok lines (:44, :52) and exits 0, so the silent skip is real. Merge clean.

The body says CI's python -I loop ran this file and skipped seven tests, but it did not: ci.yml:17 has the ^import pytest marker and ci.yml:83 skips it, while ci.yml:147-153 already ran it through pytest. This was a local-direct-run bug only, and the count before the fix is two, not three. Please correct that in the description.

AI-assisted review, no game files, no GPU.

@bobcatchris

Copy link
Copy Markdown
Contributor Author

@tupacfan04 description corrected: CI already routed this file to the pytest leg (the ^import pytest marker keeps it out of the python -I stdlib loop), so this was a direct-run-only skip; the pre-fix direct run printed two ok lines and exited 0, not three. The fix and test results are unchanged.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested e2c0672 merged with main 3faac55 on Linux (WSL2), Python 3.12.16, pytest 9.2.0: pass

python -I tests/test_amd_swizzle.py now runs the whole file: 10 tests, 10 passed, 0 failed (PIL was installed, so none skipped). python -I -m pytest tests/test_amd_swizzle.py gives the same 10 passed.

Negative control: with tests/test_amd_swizzle.py from upstream/main, direct execution prints only ok test_symbols_and_xor and ok test_rejects_code, i.e. 2 of the 10 tests (the rest are defined after the old loop). Also checked that a failing test makes the direct run exit 1 (injected assert False into test_rejects_code: 1 failed, 9 passed, rc=1), so the new SystemExit(pytest.main(...)) propagates failures.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested e2c0672 on Windows Server 2022, CPython 3.13.12: pass

  • pytest tests/test_amd_swizzle.py -> 10 passed
  • Test-only change; verifies.

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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.

4 participants