Git Product home page Git Product logo

pylint-pytest's People

Contributors

anis-campos avatar dependabot[bot] avatar dkorytkin avatar nsp avatar pierre-sassoulas avatar pre-commit-ci[bot] avatar reverbc avatar stdedos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pylint-pytest's Issues

Missing pytest.CollectReport when invoking pylint with plugin enabled

Describe the bug
PyLint generation causes stack trace when the pylint-pytest plugin is enabled.

To Reproduce
Package versions

$ pylint --version
pylint 3.0.2
astroid 3.0.1
Python 3.11.7 (main, Dec 4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]

$ pytest --version
pytest 6.2.5

pylint --output-format=json:pylint.json,parseable tests/test_add_coverage_report_to_pr.py > pylint_report.out

Folder structure

$ tree -L 2
tests/test_add_coverage_report_to_pr.py

File content

import sys
import os

import pytest
import mock
from unittest.mock import mock_open

from add_code_coverage_report_to_pr import AddCoverageReportToPR, AssembleReport
from lib.paths import Paths


@pytest.fixture(scope="module", autouse=True)
def env_reset():
    sys.argv = []


@pytest.fixture(name="env_setup")
def environment():
    os.environ['JENKINS_USER'] = "test"
    os.environ['JENKINS_AUTH'] = "test"
    os.environ['GITHUB_REPO'] = XXXXX/pr-12345'
    os.environ['REPOSOLNS_MVN_REPO'] = 'https://foo.com/artifactory/foo-mvn'
    yield 'environment'
    del os.environ['JENKINS_USER']
    del os.environ['JENKINS_AUTH']
    del os.environ['GITHUB_REPO']
    del os.environ['REPOSOLNS_MVN_REPO']
    sys.argv = []


@mock.patch('lib.wmartifactstorage.WMArtifactStorage.wmartifact_storage_factory')
def test_validate_environment(mock_fact, env_setup):
    acr = AddCoverageReportToPR()
    res = acr.validate_environment()
    assert not res
    mock_fact.assert_called()
# Additional tests removed for brevity's sake.

pylint output with the plugin

Traceback (most recent call last):
  File "/opt/homebrew/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
             ^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pylint/__init__.py", line 34, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/opt/homebrew/lib/python3.11/site-packages/pylint/lint/run.py", line 162, in __init__
    args = _config_initialization(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pylint/config/config_initialization.py", line 61, in _config_initialization
    linter.load_plugin_modules(utils._splitstrip(config_data["load-plugins"]))
  File "/opt/homebrew/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 381, in load_plugin_modules
    module.register(self)
  File "/opt/homebrew/lib/python3.11/site-packages/pylint_pytest/__init__.py", line 22, in register
    checker = importlib.import_module(module, package=os.path.basename(dirname))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/opt/homebrew/lib/python3.11/site-packages/pylint_pytest/checkers/fixture.py", line 28, in <module>
    class FixtureCollector:
  File "/opt/homebrew/lib/python3.11/site-packages/pylint_pytest/checkers/fixture.py", line 31, in FixtureCollector
    errors: Set[pytest.CollectReport] = set()
                ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pytest' has no attribute 'CollectReport'. Did you mean: 'Collector'?

(Optional) pytest output from fixture collection

$ pytest --fixtures --collect-only <path/to/test/module.py>
============================================================================== test session starts ===============================================================================
platform darwin -- Python 3.11.7, pytest-6.2.5, py-1.11.0, pluggy-1.2.0
Test order randomisation NOT enabled. Enable with --random-order or --random-order-bucket=<bucket_type>
rootdir: /Users/m0s0l1z/Projects/mre-tools, configfile: pytest.ini
plugins: random-order-1.1.0, bigquery-mock-0.1.2, mock-3.11.1, requests-mock-1.11.0
collected 25 items

<Module tests/test_add_coverage_report_to_pr.py>
  <Function test_validate_environment>
  <Function test_extract_parser_info_nexus>
  <Function test_extract_parser_info_jfrog>
  <Function test_get_coverage_rules>
  <Function test_get_coverage_rules_no_path>
  <Function test_round_to_float>
  <Function test_get_previous_report_json>
  <Function test_get_previous_report_json_value_err>
  <Function test_get_previous_report_json_no_path>
  <Function test_get_current_report_json_no_path_gen_fail>
  <Function test_get_current_report_json>
  <Function test_get_current_report_no_gen>
  <Function test_get_coverage_by_counter_curr>
  <Function test_get_coverage_by_counter_none>
  <Function test_get_coverage_by_counter_less>
  <Function test_get_coverage_by_counter_greater>
  <Function test_get_coverage_close>
  <Function test_get_coverage_close_no_latest>
  <Function test_main>
  <Function test_generate_report_if_none_fail>
  <Function test_generate_report_if_none>
  <Function test_generate_report_if_none_correct>
  <Function test_assemble_report_no_current_report>
  <Function test_assemble_report_empty_current_report>
  <Function test_assemble_report_with_current_report>

--------------------------------------------------------------- fixtures defined from pytest_bigquery_mock.plugin ----------------------------------------------------------------
bq_client_mock
    /opt/homebrew/lib/python3.11/site-packages/pytest_bigquery_mock/plugin.py:42: no docstring available


-------------------------------------------------------------- fixtures defined from test_add_coverage_report_to_pr --------------------------------------------------------------
env_reset [module scope]
    tests/test_add_coverage_report_to_pr.py:13: no docstring available

env_setup
    tests/test_add_coverage_report_to_pr.py:18: no docstring available


Status code: 0

========================================================================== 25 tests collected in 0.21s ===========================================================================

Expected behavior
The linting report is generated in both JSON and test output.

Additional context
This works just fine w/o the pylint-pytest plugin enabled in the .pylintrc file.

RecursionError when setting jobs != 1

Describe the bug
When configuring the number of Pytest workers to anything other than 1, a recursion error is seen and the linting task fails to complete.

To Reproduce

astroid==3.1.0
pylint-django==2.5.5
pylint-plugin-utils==0.8.2
pylint-pytest==1.1.7
pylint==3.1.0

Folder structure
src\namespace\module\submodule\settings_init_.py

File content

from namespace.module.submodule.event import log_event
from namespace.module.submodule.util import get_ip_address


def log_auth_event(msg, request):
    log_event("auth", dict(msg, remote_addr=get_ip_address(request)))


def log_user_logged_in(sender, user, request, **kwargs):  # pylint: disable=unused-argument
    log_auth_event(dict(username=user.username, action="login", result="success"), request)


def log_user_logged_out(sender, user, request, **kwargs):  # pylint: disable=unused-argument
    if not user:
        return
    log_auth_event(dict(username=user.username, action="logout", result="success"), request)


def log_user_login_failed(sender, credentials, request, **kwargs):  # pylint: disable=unused-argument
    log_auth_event(
        dict(username=credentials["username"], action="login", result="failure"),
        request,
    )

pylint output with the plugin

Exception on node <FunctionDef.log_user_logged_in l.9 at 0x257d06d9150> in file 'C:\dev\project_name\src\br\bls\audit\auth.py'
Traceback (most recent call last):
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\utils\ast_walker.py", line 96, in walk
    callback(astroid)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\checkers\variables.py", line 1557, in leave_functiondef
    self._check_is_unused(
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\checkers\variables.py", line 2730, in _check_is_unused
    self._check_unused_arguments(name, node, stmt, argnames, nonlocal_names)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\checkers\variables.py", line 2853, in _check_unused_arguments
    self.add_message("unused-argument", args=name, node=stmt, confidence=confidence)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\checkers\fixture.py", line 314, in patch_add_message
    FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\checkers\fixture.py", line 314, in patch_add_message
    FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\checkers\fixture.py", line 314, in patch_add_message
    FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
  [Previous line repeated 976 more times]
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\checkers\fixture.py", line 290, in patch_add_message
    and _can_use_fixture(node.parent.parent)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\utils.py", line 113, in _can_use_fixture
    if function.name.startswith("test_") or function.name.endswith("_test"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded while calling a Python object
concurrent.futures.process._RemoteTraceback:
"""
Traceback (most recent call last):
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\pylinter.py", line 830, in _check_file
    check_astroid_module(ast_node)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\pylinter.py", line 1016, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\pylinter.py", line 1068, in _check_astroid_module
    walker.walk(node)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\utils\ast_walker.py", line 94, in walk
    self.walk(child)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\utils\ast_walker.py", line 96, in walk
    callback(astroid)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\checkers\variables.py", line 1557, in leave_functiondef
    self._check_is_unused(
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\checkers\variables.py", line 2730, in _check_is_unused
    self._check_unused_arguments(name, node, stmt, argnames, nonlocal_names)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\checkers\variables.py", line 2853, in _check_unused_arguments
    self.add_message("unused-argument", args=name, node=stmt, confidence=confidence)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\checkers\fixture.py", line 314, in patch_add_message
    FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\checkers\fixture.py", line 314, in patch_add_message
    FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\checkers\fixture.py", line 314, in patch_add_message
    FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
  [Previous line repeated 976 more times]
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\checkers\fixture.py", line 290, in patch_add_message
    and _can_use_fixture(node.parent.parent)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\project_name\venv\Lib\site-packages\pylint_pytest\utils.py", line 113, in _can_use_fixture
    if function.name.startswith("test_") or function.name.endswith("_test"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded while calling a Python object

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

Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\concurrent\futures\process.py", line 256, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\concurrent\futures\process.py", line 205, in _process_chunk
    return [fn(*args) for args in chunk]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\concurrent\futures\process.py", line 205, in <listcomp>
    return [fn(*args) for args in chunk]
            ^^^^^^^^^
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\parallel.py", line 79, in _worker_check_single_file
    _worker_linter.check_single_file_item(file_item)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\pylinter.py", line 739, in check_single_file_item
    self._check_file(self.get_ast, check_astroid_module, file)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\pylinter.py", line 832, in _check_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError
"""

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

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\dev\project_name\venv\Scripts\pylint.exe\__main__.py", line 7, in <module>
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\__init__.py", line 34, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\run.py", line 211, in __init__
    linter.check(args)
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\pylinter.py", line 678, in check
    check_parallel(
  File "C:\dev\project_name\venv\Lib\site-packages\pylint\lint\parallel.py", line 153, in check_parallel
    for (
  File "C:\Program Files\Python311\Lib\concurrent\futures\process.py", line 602, in _chain_from_iterable_of_lists
    for element in iterable:
  File "C:\Program Files\Python311\Lib\concurrent\futures\_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\concurrent\futures\_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\concurrent\futures\_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
astroid.exceptions.AstroidError

Expected behavior
The plugin should result in the same output as when running in single-threaded mode.

Additional context
I'm on a 16-core machine, and I've tried with jobs=0, 1, and 2. jobs=1 is fine; everything else breaks.

Archive `PyCQA/pylint-pytest` too

So this repository is a fork of a fork: pylint-dev/pylint-pytest <- PyCQA/pylint-pytest <- reverbc/pylint-pytest.
The original repository reverbc/pylint-pytest is archived but the middle link PyCQA/pylint-pytest is not — it just has issues disabled and a few open PRs that nobody's looking into.

That lets a lot of people land on that PyCQA repo page confused as to where's the active fork. Is it possible to poke somebody from that org to archive that repo too so that there's one obvious alive repository left?

Weird recursion when upgrading from `pylint-pytest < 1.1.0` with `pylint` 2 to their latest versions

Describe the bug

Here's what I'm doing: cherrypy/cheroot@f109e85#diff-63a9c44a44acf85fea213a857769990937107cf072831e1a26808cfde9d096b9L270

To Reproduce

See cherrypy/cheroot#698. Getting the repo and running tox -e pre-commit -- pylint --all-files -vv

Expected behavior

If there's something wrong with the configuration, the error message should state that instead of spitting out tracebacks...

Additional context

I'm trying to upgrade some old linter pins to as new as I can. pylint is wrapped with pre-commit which runs on pre-commit.ci and the normal CI is also running it through tox.

Generic evergreen CI and maintenance ergonomics

P.S. Since you mentioned liking evergreen CI and maintenance ergonomics, here's a few of my GitHub Actions that you may enjoy having here:

Originally posted by @webknjaz in #15 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.