Skip to content

pylint + pylint-pytest: pylint crashed Pylint with AstroidError #126

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

Open
IsmailSAly opened this issue Mar 7, 2025 · 2 comments
Open

pylint + pylint-pytest: pylint crashed Pylint with AstroidError #126

IsmailSAly opened this issue Mar 7, 2025 · 2 comments

Comments

@IsmailSAly
Copy link

The crash happens if i define an invalid/non existing module in pytest_plugin.

The import error is expected since that module doesn't exist, but it shouldn't crash pylint.

Once i remove the problematic import pylint runs fine.

The code that causes the crash:

from dotenv import load_dotenv
import pytest
import warnings
import myTestRepo.test.options as Options
import logging
import os

logger = logging.getLogger(__name__)


# Remove pkg_resources deprecation warning
warnings.simplefilter("ignore", DeprecationWarning)

pytest_plugins = (
    "myThirdPartyytest.test.AutomatedTestFixture",
    "myThirdPartyytest.test.TestListenerFixture",
    "myThirdPartyytest.test.SignalCatchingFixture",
    "myProjectPytest.test.TestLoggingFixture",
    "myProjectPytest.file.file_manager_fixture",
    "myProject.ssh.gateway_ssh",
    "myProject.jobs.job_manager_fixture",
    "myProject.cloud.myProject_cloud_fixture",
    "myProject.email.email_manager_fixture",
    "myProject.api.sync_api_fixture",
    "myProject.gps.gps_fixture",
    "myProject.pm4_emulator.pm4_emulator_fixture",
    "myProject.playwright.playwright_fixture",
    "myProject.config.config_manager_fixture",
    "myProject.power.gateway_power_fixture",
    "myProject.api.myProject_model_fixture",
)

Command used

pylint a.py

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:
Traceback (most recent call last):
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 865, in import_plugin
    __import__(importspec)
ModuleNotFoundError: No module named 'myProjectPytest.test.TestLoggingFixture'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 788, in _lint_file
    check_astroid_module(module)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1020, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1072, in _check_astroid_module
    walker.walk(node)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 87, in walk
    callback(astroid)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pylint_pytest/checkers/fixture.py", line 129, in visit_module
    ret = pytest.main(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 159, in main
    config = _prepareconfig(args, plugins)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 346, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/helpconfig.py", line 106, in pytest_cmdline_parse
    config = yield
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1152, in pytest_cmdline_parse
    self.parse(args)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1501, in parse
    self._preparse(args, addopts=addopts)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1405, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/warnings.py", line 150, in pytest_load_initial_conftests
    return (yield)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/capture.py", line 153, in pytest_load_initial_conftests
    yield
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1230, in pytest_load_initial_conftests
    self.pluginmanager._set_initial_conftests(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 588, in _set_initial_conftests
    self._try_load_conftest(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 626, in _try_load_conftest
    self._loadconftestmodules(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 666, in _loadconftestmodules
    mod = self._importconftest(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 742, in _importconftest
    self.consider_conftest(mod, registration_name=conftestpath_plugin_name)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 823, in consider_conftest
    self.register(conftestmodule, name=registration_name)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 519, in register
    self.consider_module(plugin)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 831, in consider_module
    self._import_plugin_specs(getattr(mod, "pytest_plugins", []))
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 838, in _import_plugin_specs
    self.import_plugin(import_spec)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 867, in import_plugin
    raise ImportError(
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 865, in import_plugin
    __import__(importspec)
ImportError: Error importing plugin "myProjectPytest.test.TestLoggingFixture": No module named 'myProjectPytest.test.TestLoggingFixture'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 752, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 790, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash.

Pylint version

pylint 3.3.4
astroid 3.3.8
Python 3.10.12 (main, Feb  4 2025, 14:57:36) [GCC 11.4.0]

OS / Environment

linux (Linux)

@zenlyj
Copy link

zenlyj commented Mar 8, 2025

Thanks for the report, I was unable to reproduce the crash locally when I ran pylint on the provided code with the command that you provided: pylint a.py. I got the following output:

************* Module a
a.py:1:0: C0114: Missing module docstring (missing-module-docstring)
a.py:4:0: E0401: Unable to import 'myTestRepo.test.options' (import-error)
a.py:3:0: C0411: standard import "warnings" should be placed before third party imports "dotenv.load_dotenv", "pytest" (wrong-import-order)
a.py:5:0: C0411: standard import "logging" should be placed before third party imports "dotenv.load_dotenv", "pytest", "myTestRepo.test.options" (wrong-import-order)
a.py:6:0: C0411: standard import "os" should be placed before third party imports "dotenv.load_dotenv", "pytest", "myTestRepo.test.options" (wrong-import-order)
a.py:1:0: W0611: Unused load_dotenv imported from dotenv (unused-import)
a.py:2:0: W0611: Unused import pytest (unused-import)
a.py:4:0: W0611: Unused myTestRepo.test.options imported as Options (unused-import)
a.py:6:0: W0611: Unused import os (unused-import)

Could you share the list of installed dependencies? A minimal code snippet that causes the crash would be helpful as well.

@jacobtylerwalls
Copy link
Member

From this line of the stacktrace, I think this should be reported to pylint-pytest

File "/home/user/myProject-test/python/venv/lib/python3.10/site-packages/pylint_pytest/checkers/fixture.py", line 129, in visit_module
ret = pytest.main(

@jacobtylerwalls jacobtylerwalls transferred this issue from pylint-dev/pylint Mar 8, 2025
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

3 participants