Skip to content

docs/examples: __init__.py and helpers.py incorrectly collected as tests #796

Closed

Description

@planetf1

Summary

pytest docs/examples/ --collect-only collects four __init__.py files and helper/helpers.py as test items. They're support files, not runnable examples.

Visible after #794 restored directory-level collection, but the root cause predates that — collection is exclusion-based, so any .py file without a skip marker gets collected.

Options

A. Explicit exclusion — add these files to examples_to_skip. Quick, but doesn't prevent the same problem with future support files.

B. Opt-in collection (recommended) — require a # pytest: marker for collection. Files without one are silently skipped. Given we can't set up prerequisites or interact during execution, only files that explicitly declare themselves runnable should be collected.

All existing examples already have the marker. Changes needed:

  • Skip files with no markers in pytest_collect_file / pytest_pycollect_makemodule
  • Remove # pytest: ollama, e2e from helper/helpers.py (not a standalone example)
  • Note in AGENTS.md that the marker is required

Activity

  1. added
    bug
    on Apr 8, 2026
  2. added this to the Release 0.5.0 milestone on Apr 8, 2026
  3. self-assigned this
    on Apr 8, 2026
  4. added theissue type on Apr 8, 2026
  5. planetf1 commented on Apr 8, 2026

    @planetf1
    ContributorAuthor

    @jakelorocco @ajbozarth interested in your thoughts on option B? It feels the best compromise to me

  6. ajbozarth commented on Apr 8, 2026

    @ajbozarth
    Member

    I actually like the idea of defaulting to skip, removing the need to specify it directly

  7. planetf1 commented on Apr 9, 2026

    @planetf1
    ContributorAuthor

    Fixed alongside #794 in the same PR (#795). Went with option B (opt-in collection):

    • Examples without a # pytest: marker are silently ignored during collection
    • Removed the spurious marker from helper/helpers.py
    • Updated AGENTS.md and MARKERS_GUIDE.md to document the opt-in behaviour

    79 examples now collected (down from 84), no __init__.py or helpers.py in the output.

  8. planetf1 commented on Apr 9, 2026

    @planetf1
    ContributorAuthor

    One additional note - I've not removed the pytest lines from existing examples (where they were set to skip), and the skip marker is still supported for examples -- but the //default// is that we don't consider them a test - they're not even explicitly reported as being skipped (since that is noise).

    Given examples are hard to run, and the comment-based framework doesn't have the richness of the actual pytests (for example the memory checking conditions etc). AND given that many exaples are hard to run as-is (dependencies etc) it seems pragmatic for now

    I do think we should try to run more examples automatically - though we may move to running via shell scripts with additional setup, or may figure out a better convention for defining the equivilent of fixes to do pre/post processing for test setup (interested? I could raise issue for that to look at in future -- prioritizing WHICH examples would add focus)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugtesting

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions