TvoroG / pytest-lazy-fixture

It helps to use fixtures in pytest.mark.parametrize
MIT License
379 stars 30 forks source link

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

Open freakboy3742 opened 3 years ago

freakboy3742 commented 3 years ago

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 commented 3 years ago

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

dvzrv commented 1 year ago

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! :)

joooeey commented 1 year ago

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.