Repository navigation
fix: restore example collection during directory traversal (#794) - #795
Conversation
…e-computing#794) pytest_pycollect_makemodule only fires for files matching python_files (test_*.py) — return ExampleModule from pytest_collect_file so directory traversal collects examples.
|
The PR description has been updated. Please fill out the template for your PR to be reviewed. |
…uting#796) Examples without a marker are now silently ignored instead of being collected as tests. Removes spurious marker from helper/helpers.py and documents opt-in behaviour in AGENTS.md and MARKERS_GUIDE.md.
|
Example output: |
The previous list only covered 4 models (CI subset). Expanded to include all models needed by examples and tests, grouped by context (CI, examples, test suite) with a one-liner to pull the lot.
|
Following this fix I was able to collect and run all docs/examples -- Only 2 sofia tests failed locally , which were due to resource exhaustion (ollama models loaded like granite guardian, then no space for additional ones on a 32GB system) and will be addressed by the referenced issues. |
- pytest_pycollect_makemodule: return SkippedFile (not None) for markerless files, closing the direct-specification bypass - pytest_collect_file: narrow except to OSError, return None on failure (exclude) instead of falling through to collect - Fix stale docstring and comments from the old collection model
jakelorocco
left a comment
There was a problem hiding this comment.
thank you; I like this opt-in approach
Address code review findings from PR generative-computing#795: - Fix duplicate collection: guard pytest_collect_file with isinitpath() so directly-specified files defer to pytest_pycollect_makemodule - Remove dead try/except OSError (_extract_markers_from_file is self-contained) - Key examples_to_skip by full path instead of basename to prevent collisions across subdirectories - Use file_path.parts instead of str() substring match in pytest_pycollect_makemodule for correct path filtering - Add test/test_example_collection.py regression test verifying support files are excluded, examples are collected, and no duplicates occur Signed-off-by: Nigel Jones <[email protected]> Signed-off-by: Nigel Jones <[email protected]>
Additional hardening (commits 5–6)Code review surfaced several issues in the collection hooks we modified. All fixed in Fixes
Regression testAdded
Verification
|
|
@jakelorocco thanks for the review - rerequesting as I layered on additional changes affecting collection. |
…e-computing#794) (generative-computing#795) * fix: restore example collection during directory traversal (generative-computing#794) pytest_pycollect_makemodule only fires for files matching python_files (test_*.py) — return ExampleModule from pytest_collect_file so directory traversal collects examples. * fix: require # pytest: marker for example collection (generative-computing#796) Examples without a marker are now silently ignored instead of being collected as tests. Removes spurious marker from helper/helpers.py and documents opt-in behaviour in AGENTS.md and MARKERS_GUIDE.md. * docs: expand required Ollama models list in CONTRIBUTING.md The previous list only covered 4 models (CI subset). Expanded to include all models needed by examples and tests, grouped by context (CI, examples, test suite) with a one-liner to pull the lot. * fix: harden example collection hooks against silent failures - pytest_pycollect_makemodule: return SkippedFile (not None) for markerless files, closing the direct-specification bypass - pytest_collect_file: narrow except to OSError, return None on failure (exclude) instead of falling through to collect - Fix stale docstring and comments from the old collection model * fix: harden collection hooks and add regression test Address code review findings from PR generative-computing#795: - Fix duplicate collection: guard pytest_collect_file with isinitpath() so directly-specified files defer to pytest_pycollect_makemodule - Remove dead try/except OSError (_extract_markers_from_file is self-contained) - Key examples_to_skip by full path instead of basename to prevent collisions across subdirectories - Use file_path.parts instead of str() substring match in pytest_pycollect_makemodule for correct path filtering - Add test/test_example_collection.py regression test verifying support files are excluded, examples are collected, and no duplicates occur Signed-off-by: Nigel Jones <[email protected]> Signed-off-by: Nigel Jones <[email protected]> --------- Signed-off-by: Nigel Jones <[email protected]> Signed-off-by: Nigel Jones <[email protected]>
Misc PR
Type of PR
Description
#794 — directory collection broken:
pytest_collect_filewas returningNonefor non-skipped examples, relying onpytest_pycollect_makemoduleto handle collection. That hook only fires for files matchingpython_files(test_*.py), so examples were silently dropped during directory traversal. Fixed by returningExampleModulefrompytest_collect_file.#796 —
__init__.pyandhelpers.pyincorrectly collected: Once collection was restored, support files without a# pytest:marker were being collected as tests. Switched to opt-in — examples now require an explicit# pytest:comment to be collected. Files without one are silently ignored. Removed the spurious marker fromhelper/helpers.pyand documented the opt-in behaviour in AGENTS.md and MARKERS_GUIDE.md.Hardening (code review follow-up):
isinitpathguard)except OSErrorinpytest_collect_fileexamples_to_skipby full path instead of basename (prevents collision across subdirectories)file_path.partsinstead ofstr()substring match inpytest_pycollect_makemoduletest/test_example_collection.pyregression testCONTRIBUTING.md — expanded required Ollama models list: The previous list only covered 4 models (CI subset). Expanded to include all models needed by examples and the test suite, grouped by context with a one-liner to pull the lot.
Discovered during investigation
Running the full example suite after fixing collection surfaced two further issues:
test/conftest.pyhas warm-up/eviction hooks butdocs/examples/conftest.pyhas no equivalent.Testing