question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[prerelease] pytest.TmpdirFactory is not importable anymore

See original GitHub issue

Discovered 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:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
RonnyPfannschmidtcommented, Dec 23, 2021

Let’s provide the attribute, for python 3.7+ we can provide a deprecation using the module getattr special method

0reactions
nicoddemuscommented, Dec 23, 2021

Also, please don’t feel bad for it - you worked on a lot of very tricky topics for this release (which is very appreciated!), so it’s somewhat natural that regressions happen to bisect to one of your commits - let us know if we can help somewhere, and thanks for handling the fallout!

I second that! 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

_pytest.tmpdir — pytest documentation
"""Support for providing temporary directories to test functions.""" import os import re import sys import tempfile from pathlib import Path from typing ...
Read more >
pytest Documentation - Read the Docs
By default, pytest will not show test durations that are too small (<0.005s) unless -vv is passed on the command-line.
Read more >
Creating a temporary directory in PyTest - Stack Overflow
You can use the tmpdir fixture which will provide a temporary directory unique to the test invocation, created in the base temporary directory....
Read more >
_pytest.tmpdir — pytest documentation
import os import re import tempfile from typing import Optional import attr ... but it is not public (see https://bugs.python.org/issue25012) # Ignore type ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found