Skip to content

--import-mode=importlib causes tests to import a class with a different id #10341

Closed
@rectalogic

Description

@rectalogic
  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: collectionrelated to the collection phasetype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions