Closed dstansby closed 5 months ago
Ah. The conflicts are from me in
(Soz)
Thanks for comments! I won't have time to fix this in the next couple of weeks, so someone else feel free to take over if you're keen to get this in quicker!
At the moment the approach of making the
tests
directory a package by adding an__init__.py
(presumably so we can use a relative import forhelpers
module) seems to break the ability to run tests directly by runningpytest
orpytest -s
from the root of the repository (with the latter being what we currently recommend in the developer notes in the README), though tests do still run fine usingtox
. Specifically I get the following errors on test collection_______________________________________ ERROR collecting tests/test_git_init.py ________________________________________ ImportError while importing test module '.../python-tooling/tests/test_git_init.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: tests/test_git_init.py:8: in <module> from .helpers import gen_package E ModuleNotFoundError: No module named 'tests' ______________________________________ ERROR collecting tests/test_package_gen.py ______________________________________ ImportError while importing test module '.../python-tooling/tests/test_package_gen.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: tests/test_package_gen.py:6: in <module> from .helpers import gen_package E ModuleNotFoundError: No module named 'tests'
I guess this is because the
tests
package is not being added to the Python path by pytest and so the relative import doesn't work?I think we can avoid having
tests
be a package by either wrapping thegen_package
function into a fixture inconftest.py
import pytest def _gen_package( path: pathlib.Path, project_config: dict[str, str] ) -> subprocess.CompletedProcess[str]: ... @pytest.fixture def gen_package(): return _gen_package
and having the tests which use it accept a
gen_package
argument [...]
I went for your first suggestion. Adding fixtures as defaults to functions returned by fixtures ended up a bit messy. This way is explicit-er and only repeats one line in the two tests... so not too terrible?
This makes the tests a bit easier to extend by:
functionfixture to generate a package from a given set of configuration options (intests/helpers.py
conftest.py
)conftest.py
. This makes it easier to see what config each test is using next to the actual test.