pylint-dev / pylint-pytest

A Pylint plugin to suppress pytest-related false positives.
https://pypi.org/project/pylint-pytest/
MIT License
16 stars 3 forks source link

Monsensical `cannot-enumerate-pytest-fixtures` error #68

Open stdedos opened 5 months ago

stdedos commented 5 months ago

I'm eager to reproduce this if I can. I cloned scriv and ran python -m tox -e quality and it passed, without any output suggesting the scriv command ran.

I ran without tox as pylint src/scriv tests docs setup.py after installing pylint_pytest, and with pytest 7.4.2, and the files linted, although they threw lots of errors like:

************* Module scriv.util
src/scriv/util.py:12:0: E0401: Unable to import 'click_log' (import-error)
************* Module scriv.cli
src/scriv/cli.py:6:0: E0401: Unable to import 'click_log' (import-error)
************* Module scriv.linkcheck
src/scriv/linkcheck.py:7:0: E0401: Unable to import 'markdown_it' (import-error)
...
************* Module tests.test_ghrel
tests/test_ghrel.py:1:0: F6401: pylint-pytest plugin cannot enumerate and collect pytest fixtures. Please run `pytest --fixtures --collect-only tests/test_ghrel.py` and resolve any potential syntax error or package dependency issues. stdout: . stderr: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/_pytest/config/__init__.py:324: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: helpconfig, Hook: pytest_cmdline_parse
ConftestImportFailure: ModuleNotFoundError: No module named 'responses' (from /Users/jwalls/scriv/tests/conftest.py)
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config = pluginmanager.hook.pytest_cmdline_parse(
ImportError while loading conftest '/Users/jwalls/scriv/tests/conftest.py'.
tests/conftest.py:10: in <module>
    import responses
E   ModuleNotFoundError: No module named 'responses'
. (cannot-enumerate-pytest-fixtures)

Once I can reproduce, I'm happy to bisect the pylint or astroid changes that could be to blame. I wonder if knowing your installed version of pytest would help. Any other tips for reproducing would be appreciated. Thanks.

Originally posted by @jacobtylerwalls in https://github.com/pylint-dev/pylint-pytest/issues/67#issuecomment-2125770504

stdedos commented 5 months ago

For completeness:

This is also a nice reproducer. I have been having a similar issue in a proprietary code that threw more or less the same cannot-enumerate-pytest-fixtures error.

I have been trying to troubleshoot it with https://github.com/pylint-dev/pylint-pytest/tree/playground/impr/cannot-enumerate-pytest-fixtures. In any case - I don't get how is it possible that the current environment "disappears" and neither requests nor this.namespace.package.sub.module "exist" anymore.

Funny thing is that, pytest alone is able to figure the issue out (no variant of pytest --fixtures --collect-only ... reveals any issue, nor does it fail pytest).

To be honest, I have been blocking v2 behind tl;dr this issue and pytest v8 😶‍🌫️ (my time being limited, and no progress in figuring out the logic behind this :confused:)

ANY help is more than welcome :pray: (from people that know how module discovery works? pytest internals?)