We’d like to run our tests on an installed package instead of the development version, as we delete some files in our build process. We therefore don’t use editable installs.
I think the problem is that there seems to be no way to configure the import root used with the importlib import mode. The project rootdir gets passed here instead of something user configurable:
|
module = import_path( |
|
self.path, |
|
root=self.config.rootpath, |
|
mode=self.config.getoption("importmode"), |
|
) |
Which means that the following code will run module_name = module_name_from_path('<rootdir>/src/anndata/_types.py', '<rootdir>'), i.e. module_name = 'src.anndata._types' when it should be 'anndata._types'
|
if mode is ImportMode.importlib: |
|
module_name = module_name_from_path(path, root) |
Without src/ layout, this works accidentally, as the module_name happens to match the real module name, and the module only gets imported once.
Pytest 7.4.2
reproducer
We’d like to run our tests on an installed package instead of the development version, as we delete some files in our build process. We therefore don’t use editable installs.
I think the problem is that there seems to be no way to configure the import root used with the importlib import mode. The project rootdir gets passed here instead of something user configurable:
pytest/src/_pytest/doctest.py
Lines 545 to 549 in c34eaaa
Which means that the following code will run
module_name = module_name_from_path('<rootdir>/src/anndata/_types.py', '<rootdir>'), i.e.module_name = 'src.anndata._types'when it should be'anndata._types'pytest/src/_pytest/pathlib.py
Lines 524 to 525 in 9f3bdac
Without
src/layout, this works accidentally, as themodule_namehappens to match the real module name, and the module only gets imported once.Pytest 7.4.2