Skip to content

Python adapter: find pytest test files #55

Closed

Description

@adityankale190895

Part of the Python (pytest) adapter: #61.

Before DiffCI can select Python tests, it needs to know which files pytest treats as tests. This issue is only that piece: no import graph, no commands.

Scope

  • A small function in src/repo/adapters/python.ts (new file) that takes the repository's file list, pytest configuration, and (when known) the paths the CI command passes to pytest, and returns the test files.
  • Default discovery: test_*.py and *_test.py.
  • Honour testpaths and python_files from pytest.ini, pyproject.toml ([tool.pytest.ini_options]), tox.ini or setup.cfg.
  • testpaths is only where pytest starts looking by default, not a filter: paths passed on the command line override it. Use the command's paths when there are any, otherwise testpaths, otherwise the repository root.
  • Return a blocker for anything it can't read statically (for example a conftest.py that defines pytest_collect_file, or python_files set from a plugin), and when the pytest invocation is unknown or can't be parsed. Never return a list built only from testpaths in that case.

Done when

  • Unit tests cover: default layout, src/ layout, a custom testpaths, a custom python_files, testpaths = checks with the command passing tests (only tests/ files returned), and one unsupported case that returns a blocker.
  • The function is exported but not yet registered in REPOSITORY_ADAPTERS.

Safety rule: when the adapter is unsure, it adds a blockers entry so DiffCI runs the full suite. An empty graph must never look like "nothing affected".


New to DiffCI? Read the adapter guide and CONTRIBUTING.md. Sign off commits with git commit -s. Comment here to claim it, and ask questions on the issue at any point.

Activity

  1. added
    enhancement
    good first issue
    on Oct 29, 2026
  2. robertwmccarty-caelum commented on Oct 30, 2026

    @robertwmccarty-caelum
    Contributor

    Test-backed discovery boundary for #55 (not claiming or reserving the implementation).

    I ran six isolated synthetic repositories with pytest 9.0.2, PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m pytest --collect-only -q -p no:cacheprovider, and asserted the collected node IDs (all six checks passed):

    Fixture Observed collection
    Default test_root.py, alpha_test.py, src/test_source.py, plus tests/spec_ignored.py First three collected; spec_ignored.py excluded
    pytest.ini: testpaths = checks; checks/test_inside.py + tests/test_outside.py Only checks/test_inside.py
    Same fixture, invoked with explicit argument tests Only tests/test_outside.py — explicit CLI path overrides testpaths
    pyproject.toml: [tool.pytest.ini_options] python_files = ["spec_*.py"] tests/spec_math.py collected; tests/test_ignored.py excluded
    tox.ini: [pytest] testpaths = qa; python_files = check_*.py (on separate lines) Only qa/check_math.py
    setup.cfg: [tool:pytest] testpaths = qa; python_files = check_*.py (on separate lines) Only qa/check_math.py

    Selection-safety implication: testpaths is a default search starting point, not a permanent exclusion rule. A selector that drops every test outside testpaths can miss tests when the actual CI command supplies positional paths. For this initial discovery-only function, either model the CI invocation's collection roots explicitly or return a blocker when the invocation is unknown; do not treat an empty result as proof that no tests exist. This is consistent with the issue's full-suite fallback rule.

    Minimal reproduction for the third case:

    mkdir -p checks tests
    printf '[pytest]\ntestpaths = checks\n' > pytest.ini
    printf 'def test_ok(): assert True\n' > checks/test_inside.py
    printf 'def test_ok(): assert True\n' > tests/test_outside.py
    PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m pytest --collect-only -q -p no:cacheprovider
    # checks/test_inside.py::test_ok
    PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m pytest --collect-only -q -p no:cacheprovider tests
    # tests/test_outside.py::test_ok

    Upstream references: pytest configuration reference and test discovery.

    These are local pytest observations, not DiffCI integration tests; no repository code or CI configuration was changed. Prepared with AI assistance for a human BuddyLists / Linked AIs operator, not an independently operated agent account.

  3. adityankale190895 commented on Oct 30, 2026

    @adityankale190895
    MemberAuthor

    Thanks @robertwmccarty-caelum, the six collection checks are a great reference, especially the third one. I hadn't accounted for an explicit command-line path overriding testpaths.

    Adding this to the scope:

    • testpaths is the default place pytest starts looking, not a filter. The discovery function should take the collection paths from the CI command when it knows them, and fall back to testpaths, then the repo root, only when the command passes no paths.
    • If the invocation is unknown or can't be parsed, return a blockers entry rather than a list built only from testpaths.
    • Add a unit test for "testpaths = checks, but the command passes tests" alongside the existing ones.

    Your fixtures (the default layout, pyproject, tox.ini and setup.cfg variants) map directly onto the "Done when" list, so whoever claims this can reuse them. Still open. Comment to claim.

  4. adityankale190895 commented on Nov 7, 2026

    @adityankale190895
    MemberAuthor

    Shipped in CLI 0.3.33 (Core 0fd9ed0) as part of the pytest adapter. Real-repository feedback is tracked in #75.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    adapterenhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions