conftest: install the piecewise finder before the translator is imported #2905
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2905"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T17:00:19Z.
mainis red on theCIworkflow for one test, and this is why:test_support_installs_the_finder_only_where_the_tokenizer_is_slowasserts which loader the translator was imported through, and under pytest it is always the wrong one.tests/semantic/support.pydoes the right thing — it installsToolsFinderjust beforePathFinderand then importsrdna2spirvthrough it — buttests/conftest.pyimportsrdna2spirvfirst, for its own fixtures:A finder can only take an import it is in
sys.meta_pathfor when the module is first asked for. By the timesupportruns,rdna2spirvis insys.moduleswithPathFinder's loader, andsupport's ownimport rdna2spirvis a no-op.That is also why the same test is green run the other way:
python tests/test_piecewise_parse.pyhas no conftest, sosupportimports first and the finder takes it. Same code, two answers, decided by which runner started it.The change:
conftestputstests/semanticon the path and importssupportbeforerdna2spirv.supportimportsrdna2spirvitself, so the line after it stays and becomes the import that already happened — no fixture changes, no reloads, and nothing that depends on the test's own order.Measured on
main85ec1d33b(CPython 3.14 here, whereneeded()is true):What this does not touch: the finder, the loader,
piecewise_parse, or which Python versions need any of it. It only makes the conftest stop taking the import out from under it.AI-assisted: yes — DeepSeek v4.1 (flash), which ran the test both ways to find out why it disagreed with itself.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T17:43:48Z.
Independent pytest import-order check at
74da6c8a4+d2a564b66.I ran
python -m pytest -p no:cacheprovider -q tests/test_piecewise_parse.py tests/test_cpu_ref.pyon both revisions. With CPython 3.14.7, main had 64 passes and failed the loader assertion because it usedSourceFileLoader. Main plus this PR passed all 65 tests. Each run also passed 1,870 subtests. With CPython 3.14.10, both revisions passed all 65 tests and 1,870 subtests. Runningpython tests/test_piecewise_parse.pydirectly passed all 26 tests in each of the four runs.MEASURED with synthetic inputs. AI-assisted (Codex).
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T17:48:04Z.
Review: COMMENTED
Confirmed against current
origin/main(0d4cbd589):pytest tests/test_piecewise_parse.pyis 1 failed / 25 passed there and 26/26 here, whilepython -I tests/test_piecewise_parse.pyis green on both. The diagnosis is right —tests/semantic/support.py:58-60can only intercept the first import, andtests/conftest.py:30used to win it, leavingSourceFileLoader. Mutation-checked: swappingimport supportback afterimport rdna2spirvturns the test red with the original assertion, so the ordering line is what carries the fix.One thing worth saying in the comment: this installs
ToolsFinderand setssys.dont_write_bytecode = True(viasupport.py:55) for the whole pytest session, so every latertools/*.pyimport in unrelated files (test_wave_diff,test_mc_command, …) is compiled throughPiecewiseLoader, not just the translator. I spot-checked code-object equality forttpf_mips,mc_command,shader_disasmandttpf_assets, and a 13-file tools-importing batch is green (196 passed, 12 skipped), so it is fine — but stating the wider scope in the comment would save the next reader the question.Minor: the version range would read better as
3.13.15than "3.12 to 3.14.7" if that is the actual boundary you measured, and the conftest now pays thesupport+spirv_mini_interpimport on every run (test_wave_diff.pywent 2.84 s → 3.44 s).Ordering is not fragile: it passes alone, after
test_wave_diffcollects first, fromtests/as cwd, and with-p no:cacheprovider. Merge is clean, and the four commits main gained since the base touch only Rust andd3d12/docs/switches.md.Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T18:11:59Z.
Both notes taken.
The
sys.dont_write_bytecode = True. You are right that it belongs in the description: importingsupportat conftest time does two things, not one - it putsToolsFinderinsys.meta_pathand it setssys.dont_write_bytecode = True(support.py:55), and the second is a process-wide effect that now happens before any test runs rather than at the first translator import. It is the same setting the semantic tests already ran under, and it stops pytest from dropping__pycache__intotree under test; I have added it to the body rather than leaving it for someone to discover from a stale.pycdirectory.The version range. Fair - the thing that makes it read oddly is that two ranges are involved (3.12 up to before 3.13.16, and 3.14 up to before 3.14.8), so neither
3.13.15nor3.14.7alone is the boundary. The body now says exactly that instead of a shorthand that reads like one range.And the ordering evidence is useful (alone, after
test_wave_diffcollects first, fromtests/as cwd, and with-p no:cacheprovider): that is the shape I could not check from here, because the failure only appears under pytest's conftest.Measured here (CPython 3.14, where
needed()is true):pytest tests/test_piecewise_parse.py26 passed; the same file aspython tests/test_piecewise_parse.pyOK; the five filesci.ymlruns for this area plustest_cpu_ref, 81 passed.Written with an AI assistant.