Skip to content

Breaks with pytest 7 due to private imports #533

Closed
@The-Compiler

Description

@The-Compiler

In pytest-dev/pytest#9415, we discovered that this plugin breaks with pytest 7.0.0rc1:

  File ".../pytest_postgresql/factories/process.py", line 27, in <module>
    from _pytest.tmpdir import TempdirFactory
ImportError: cannot import name 'TempdirFactory' from '_pytest.tmpdir' (/usr/lib/python3.10/site-packages/_pytest/tmpdir.py)

This is due to this class moving to a different place in pytest internally. Other places use similar private imports which still work, for now:

tests/test_postgres_options_plugin.py
3:from _pytest.pytester import Pytester

src/pytest_postgresql/config.py
1:from _pytest.fixtures import FixtureRequest

src/pytest_postgresql/plugin.py
22:from _pytest.config.argparsing import Parser

tests/test_executor.py
5:from _pytest.fixtures import FixtureRequest

src/pytest_postgresql/factories/client.py
22:from _pytest.fixtures import FixtureRequest

src/pytest_postgresql/factories/noprocess.py
23:from _pytest.fixtures import FixtureRequest

src/pytest_postgresql/factories/process.py
26:from _pytest.fixtures import FixtureRequest
27:from _pytest.tmpdir import TempdirFactory

With pytest 7.0.0, those types become publicly available, so it's recommended to import them from pytest directly instead, perhaps via a small compat layer which can be dropped once support for pytest<7 isn't relevant anymore.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions