Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy can't discover pytest.lazy_fixture under pytest 6 #51

Open
freakboy3742 opened this issue Mar 8, 2021 · 3 comments
Open

mypy can't discover pytest.lazy_fixture under pytest 6 #51

freakboy3742 opened this issue Mar 8, 2021 · 3 comments

Comments

@freakboy3742
Copy link

freakboy3742 commented Mar 8, 2021

If you have a test suite that uses pytest.lazy_fixture, and you're using pytest 6.0.0+, and you run mypy over your test suite, mypy complains with the error:

test/test_something.py:42: error: Module has no attribute "lazy_fixture"

The test suite itself passes without any problems; it is only the type checking of mypy that fails.

This problem does not exist on pytest 5.4.3 or earlier.

I presume something has changed in the plugin registration process that prevents mypy from seeing the lazy_fixture attribute.

@tadeu
Copy link

tadeu commented Jun 4, 2021

importing it directly from pytest_lazyfixture import lazy_fixture (and using lazy_fixture directly) seems to be a workaround

kasium added a commit to kasium/typeshed that referenced this issue Jul 9, 2021
This change will add stubs for pytest-lazyfixture. It is particual useful for projects which type their tests and use pytest-lazyfixture.
The included functions and classes are the scope which can be considered documented by the module. Any other function is related to pytest hook implementations and are normally not called by an user.

Please note, that if a user uses 'pytest.lazy_fixture' these stubs will not work. As recommneded in TvoroG/pytest-lazy-fixture#51 the package needs to imported directly.
Akuli added a commit to python/typeshed that referenced this issue Jul 9, 2021
This change will add stubs for pytest-lazyfixture. It is particual useful for projects which type their tests and use pytest-lazyfixture.
The included functions and classes are the scope which can be considered documented by the module. Any other function is related to pytest hook implementations and are normally not called by an user.

Please note, that if a user uses 'pytest.lazy_fixture' these stubs will not work. As recommneded in TvoroG/pytest-lazy-fixture#51 the package needs to imported directly.

Co-authored-by: Akuli <akuviljanen17@gmail.com>
@dvzrv
Copy link

dvzrv commented Nov 23, 2022

Without doing what @tadeu proposes, mypy (>=0.991) complains about this now:

error: "object" not callable  [operator]

@TvoroG could you add proper typing for this project (see the typeshed stubs above)? It would make this issue go away generically! :)

archlinux-github pushed a commit to archlinux/repod that referenced this issue Nov 23, 2022
tests/common/test_models.py:
It seems that without importing from pytest_lazyfixture, lazy_fixture
types are not properly detected:
TvoroG/pytest-lazy-fixture#51
archlinux-github pushed a commit to archlinux/repod that referenced this issue Nov 23, 2022
tests/common/test_models.py:
It seems that without importing from pytest_lazyfixture, lazy_fixture
types are not properly detected:
TvoroG/pytest-lazy-fixture#51
@joooeey
Copy link

joooeey commented Jan 25, 2023

The pytest devs consider monkey-patching invalid:

We no longer recommend to "install" things into the pytest namespace. +1
One of the reasons is static type checkers.

Hence, the solution (and not just a workaround) is this:

importing it directly from pytest_lazyfixture import lazy_fixture (and using lazy_fixture directly) seems to be a workaround

This is also the way it's documented in the pytest-lazyfixture docs. So I think y'all can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants