Skip to content

pytest fails to collect the Python client tests: pytest.ini's pythonpath does not match the tests' import style #201

Description

@dmccoystephenson

Summary

Running pytest from the repository root fails during collection for all eight Python test modules:

src/test/python/preponderous/viron/models/test_entity.py:6: in <module>
    from src.main.python.preponderous.viron.models.entity import Entity
E   ModuleNotFoundError: No module named 'src'

Cause

The two settings disagree about how the client is imported.

pytest.ini puts the package directories themselves on the path:

[pytest]
pythonpath = ./src/main/python
             ./src/test/python

which supports from preponderous.viron.models.entity import Entity. Every test module instead imports through the full path from the repository root, for example src/test/python/preponderous/viron/models/test_entity.py:6:

from src.main.python.preponderous.viron.models.entity import Entity

which needs the repository root on the path — and the root is never added. There are no __init__.py files under src/test/python, so pytest's default prepend import mode inserts each test module's own directory rather than the root, and src stays unresolvable.

Impact

Developer experience and the loop's ability to verify client changes, not correctness of shipped code. The tests themselves are fine: all 107 pass once the path is right (pytest --import-mode=importlib is one way through). CI does not cover the Python client — .github/workflows/ci.yml runs only ./mvnw compile -B and ./mvnw test -B — so nothing catches this, and the documented command simply does not work for a newcomer.

Suggested fix

Pick one import style and make the configuration agree with it. Adding the root:

pythonpath = .

makes the existing src.main.python.... imports resolve with no change to any test. Rewriting the imports to preponderous.viron.... and keeping the current pythonpath is the tidier option but touches all eight modules, and it is worth deciding deliberately since the package layout is mirrored from the Java side.

Worth resolving alongside a decision about whether CI should run the Python suite at all; today a green CI says nothing about the client.

This issue body was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions