The goal here is to make helpers (forgejo mini-client, random word generator) used by the tests importable. These helpers may be replaced by external dependencies in the future. The chosen layout is the src layout with tests on the side. Although this project is all about the tests, I think it still makes sense for the helpers to be clearly separated and for the tests to import internal helpers from the package itself. The src layout requires installation of the project to be able to run its code, but this should happen automatically with uv run pytest (under one condition: a build system must be defined in pyproject.toml). Uv uses presence of the build system in configuration to determine whether to install the project or just its dependencies. Here, uv_build is chosen (ie. what uv init would do by default). On that note, I might be wrong, but it seems that uv_build requires the src layout while hatchling would be fine with a flat layout as well. Taken together, this makes `uv run pytest --import-mode=importlib` work without issues. The importlib import mode is not default, but recommended for new projects, so it is added to the pytest.toml configuration file. As far as refactoring goes: ForgejoMiniClient and Words classes now go into their own files under forgejo-integration-testing. What led me to this: - https://docs.pytest.org/en/stable/explanation/goodpractices.html - https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/ - https://docs.astral.sh/uv/concepts/projects/config/#build-systems - https://yaleman.org/post/2024/2024-10-15-uv-and-pytest/
2 lines
47 B
TOML
2 lines
47 B
TOML
[pytest]
|
|
addopts = ["--import-mode=importlib"]
|