Here is a minimal repo that reproduces this issue https://github.com/rectalogic/pytest-importlib-bug
It is configured for poetry, you can poetry install then poetry run pytest -s to reproduce. See the README at the above repo for example output.
When using both --doctest-modules and --import-mode=importlib with pytest, it imports the same class as two different classes.
In the test repo above, you can see the id() of the class imported in test_google_workspace.py is different than the one in google_workspace.py - and then the test assertion fails because the two Event classes are actually different.
Remove either of the above pytest options and tests pass.
Running the test in isolation also passes.
pytest 7.1.3
macOS 12.6
pip list output:
Package Version Editable project location
---------- ------- -----------------------------------------------------------------------
attrs 22.1.0
iniconfig 1.1.1
packaging 21.3
pip 22.2.2
pluggy 1.0.0
py 1.11.0
pybug 0.1.0 /Users/aw/Projects/cureatr/dev/cureatr/experiments/pytest-importlib-bug
pyparsing 3.0.9
pytest 7.1.3
setuptools 65.3.0
tomli 2.0.1
wheel 0.37.1
pip listfrom the virtual environment you are usingHere is a minimal repo that reproduces this issue https://github.com/rectalogic/pytest-importlib-bug
It is configured for poetry, you can
poetry installthenpoetry run pytest -sto reproduce. See the README at the above repo for example output.When using both
--doctest-modulesand--import-mode=importlibwith pytest, it imports the same class as two different classes.In the test repo above, you can see the
id()of the class imported intest_google_workspace.pyis different than the one ingoogle_workspace.py- and then the test assertion fails because the twoEventclasses are actually different.Remove either of the above pytest options and tests pass.
Running the test in isolation also passes.
pytest 7.1.3
macOS 12.6
pip listoutput: