-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Discovered in dbfixtures/pytest-postgresql#533 (comment) via #9415:
Doing e.g. python3 -c "import pytest; pytest.TempdirFactory" fails since 5e883f5. This is a bit similar to #9396, but #9400 won't help with this one.
Test modules often use pytest.TempdirFactory for type annotations - in fact, that's why that was added in 6.2.0.
However, it being set from a plugin means that:
a) Test modules aren't even importable anymore outside of pytest - in case of pytest-postgresql, this breaks an importability check, but I can imagine various other things breaking...
b) Perhaps more importantly, static analysis in IDEs or tools like mypy aren't aware anymore that the attribute exists - however, after all, that's the whole point of it existing, and lots of projects use it that way. (Some import it from _pytest.tmpdir, probably because they did that before 6.2.0 - I'm not too worried about those, they knew what they're in for)
Reproducer:
from pytest import TempdirFactory
def test_nothing(tmpdir: TempdirFactory):
passFails with mypy:
test_x.py:1: error: Module "pytest" has no attribute "TempdirFactory"; maybe "TempPathFactory"?
Found 1 error in 1 file (checked 1 source file)
What to do? I suppose as a stop-gap until we want to distribute the plugin independently from pytest, we could import the class from the plugin or so?