[prerelease] pytest.TmpdirFactory is not importable anymore
See original GitHub issueDiscovered in https://github.com/ClearcodeHQ/pytest-postgresql/issues/533#issuecomment-999567968 via #9415:
Doing e.g. python3 -c "import pytest; pytest.TempdirFactory"
fails since 5e883f51959f900fcf985493ce2d09e07bad7e00. 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):
pass
Fails 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?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Let’s provide the attribute, for python 3.7+ we can provide a deprecation using the module getattr special method
I second that! 👍