Open Jaakkonen opened 3 years ago
Commenting the
my_fixture
out intest_thing.py
makes pylint-pytest pass but executing tests fails tomy_fixture
not being found.
This is weird and sounds like a bug in pytest itself. The import from .fixtures
evaluates the fixtures
module meaning that both fixtures must get registered no matter what. My guess is that the scope of the default fixtures is the fixtures.py
module somehow and by exposing them to the global scope of test_thing.py
, it makes them available.
FWIW I think that what you're trying to do is an antipattern and you should probably move the fixture imports or even their declarations to conftest.py
instead. I don't think that pylint-pytest
should encourage this usage pattern.
AFAIK, pytest
will only register the fixtures that are available in the locals()
of the current module, or from locals()
of the magic conftest.py
. If we don't explicitly import the my_fixture
in this module it will not load it.
FWIW I think that what you're trying to do is an antipattern and you should probably move the fixture imports or even their declarations to
conftest.py
instead. I don't think thatpylint-pytest
should encourage this usage pattern.
Yes I do agree with that. In general we should register the fixtures to conftest.py
, and we do avoid the plugin from complaining unused imported fixtures in conftest.py
at https://github.com/reverbc/pylint-pytest/blob/5804967/pylint_pytest/checkers/fixture.py#L217-L222
I'm wondering if there's a specific use case that you don't want to import the fixtures into conftest.py
?
When you have a fixture that is local to the test module, not global for the whole test session. Also, you may override the global fixtures with some values specific to your module (by redefining fixtures with the same name).
When you have a fixture that is local to the test module, not global for the whole test session. Also, you may override the global fixtures with some values specific to your module (by redefining fixtures with the same name).
@webknjaz sorry for the confusion - that question was actually addressed to @Jaakkonen. I'm interested in the pattern they're using (manually import fixtures from fixtures.py
vs. automatically imported by contest.py
).
I'm wondering if there's a specific use case that you don't want to import the fixtures into conftest.py?
Essentially trying not to have implicit dependencies.
I think one option would be to make pylint-pytest
to give a warning which is not the pylint default unused-import
if fixtures are imported explicitly (and not via conftest.py
) like here. That would allow projects that want to use explicit imports of fixtures to ignore that warning without throwing # pylint: disable=unused-import
in all places fixtures are being imported.
Describe the bug When using a imported fixture with dependencies its dependencies need to be imported too. These imported dependencies are reported as unused by pylint-pytest.
To Reproduce Package versions
(add any relevant pylint/pytest plugin here)
Folder structure
File content
pylint output with the plugin
(Optional) pytest output from fixture collection
Expected behavior A linting warning is not raised from fixtures imported as dependencies if the dependent fixture is being used.
Additional context Commenting the
my_fixture
out intest_thing.py
makes pylint-pytest pass but executing tests fails tomy_fixture
not being found.