Skip to content

Commit

Permalink
Update pytest requirement from ~=7.4 to ~=8.2 (#9576)
Browse files Browse the repository at this point in the history
Updates the requirements on [pytest](https://github.com/pytest-dev/pytest) to permit the latest version.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](pytest-dev/pytest@7.4.0...8.2.0)

---
updated-dependencies:
- dependency-name: pytest
  dependency-type: direct:production
...

Prevent some test pollution created by mocking ``sys.exit``, and some name clashes.

Commit originally responsible for issue from pytest is pytest-dev/pytest@a21fb8. We still don't know what exactly caused the issue that made the test pollution apparent.

Used a bisection and suggestion from pytest-dev/pytest#11138 (comment) to fix it.

With 'pytest' (launching the whole pylint test suite):
FAILED tests/test_precedence.py::test_package - AssertionError: E: 21: Module 'package.AudioTime' has no 'DECIMAL' member<function Equals.<locals>.<lambda> at 0x76c566741750>

With 'pytest tests/test_precedence.py':
tests/test_precedence.py .                                                                                                                                                                           [100%]

============================================================================================ 1 passed in 1.04s =============================================================================================

With 'python tests/test_precedence.py':
Checked ['package.__init__'] successfully
Checked ['precedence_test'] successfully
Checked ['import_package_subpackage_module'] successfully
Checked ['pylint.checkers.__init__'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/classdoc_usage.py'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/module_global.py'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/decimal_inference.py'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/absimp/string.py'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/bad_package'] successfully
---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <[email protected]>
Co-authored-by: Daniël van Noord <[email protected]>
  • Loading branch information
3 people authored Jun 4, 2024
1 parent a94105e commit ba33325
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 35 deletions.
22 changes: 9 additions & 13 deletions pylint/testutils/configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import unittest
from pathlib import Path
from typing import Any, Dict
from unittest.mock import Mock

from pylint.lint import Run

Expand Down Expand Up @@ -135,18 +134,15 @@ def get_expected_output(

def run_using_a_configuration_file(
configuration_path: Path | str, file_to_lint: str = __file__
) -> tuple[Mock, Mock, Run]:
) -> Run:
"""Simulate a run with a configuration without really launching the checks."""
configuration_path = str(configuration_path)
args = ["--rcfile", configuration_path, file_to_lint]
# We do not capture the `SystemExit` as then the `runner` variable
# would not be accessible outside the `with` block.
with unittest.mock.patch("sys.exit") as mocked_exit:
# Do not actually run checks, that could be slow. We don't mock
# `PyLinter.check`: it calls `PyLinter.initialize` which is
# needed to properly set up messages inclusion/exclusion
# in `_msg_states`, used by `is_message_enabled`.
check = "pylint.lint.pylinter.check_parallel"
with unittest.mock.patch(check) as mocked_check_parallel:
runner = Run(args)
return mocked_exit, mocked_check_parallel, runner
# Do not actually run checks, that could be slow. We don't mock
# `PyLinter.check`: it calls `PyLinter.initialize` which is
# needed to properly set up messages inclusion/exclusion
# in `_msg_states`, used by `is_message_enabled`.
check = "pylint.lint.pylinter.check_parallel"
with unittest.mock.patch(check):
runner = Run(args, exit=False)
return runner
2 changes: 1 addition & 1 deletion requirements_test_min.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
astroid==3.2.2 # Pinned to a specific version for tests
typing-extensions~=4.12
py~=1.11.0
pytest~=7.4
pytest~=8.2
pytest-benchmark~=4.0
pytest-timeout~=2.3
towncrier~=23.11
Expand Down
10 changes: 4 additions & 6 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ def test_can_read_toml_env_variable(tmp_path: Path, file_to_lint_path: str) -> N
)
env_var = "tmp_path_env"
os.environ[env_var] = str(config_file)
mock_exit, _, runner = run_using_a_configuration_file(
f"${env_var}", file_to_lint_path
)
mock_exit.assert_called_once_with(0)
runner = run_using_a_configuration_file(f"${env_var}", file_to_lint_path)
assert runner.linter.msg_status == 0
check_configuration_file_reader(runner)


Expand Down Expand Up @@ -226,7 +224,7 @@ def test_disable_before_enable_all_takes_effect() -> None:
runner = Run(["--disable=fixme", "--enable=all", str(FIXME_MODULE)], exit=False)
assert not runner.linter.stats.by_msg

_, _, toml_runner = run_using_a_configuration_file(
toml_runner = run_using_a_configuration_file(
HERE
/ "functional"
/ "toml"
Expand All @@ -239,7 +237,7 @@ def test_enable_before_disable_all_takes_effect() -> None:
runner = Run(["--enable=fixme", "--disable=all", str(FIXME_MODULE)], exit=False)
assert runner.linter.stats.by_msg

_, _, toml_runner = run_using_a_configuration_file(
toml_runner = run_using_a_configuration_file(
HERE
/ "functional"
/ "toml"
Expand Down
12 changes: 4 additions & 8 deletions tests/config/test_functional_config_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ def default_configuration(
) -> PylintConfiguration:
empty_pylintrc = tmp_path / "pylintrc"
empty_pylintrc.write_text("")
mock_exit, _, runner = run_using_a_configuration_file(
str(empty_pylintrc), file_to_lint_path
)
mock_exit.assert_called_once_with(0)
runner = run_using_a_configuration_file(str(empty_pylintrc), file_to_lint_path)
assert runner.linter.msg_status == 0
return runner.linter.config.__dict__


Expand Down Expand Up @@ -88,10 +86,8 @@ def test_functional_config_loading(
warnings.filterwarnings(
"ignore", message="The use of 'MASTER'.*", category=UserWarning
)
mock_exit, _, runner = run_using_a_configuration_file(
configuration_path, file_to_lint_path
)
mock_exit.assert_called_once_with(expected_code)
runner = run_using_a_configuration_file(configuration_path, file_to_lint_path)
assert runner.linter.msg_status == expected_code
out, err = capsys.readouterr()
# 'rstrip()' applied, so we can have a final newline in the expected test file
assert expected_output.rstrip() == out.rstrip(), msg
Expand Down
12 changes: 10 additions & 2 deletions tests/lint/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from shutil import copy, rmtree
from unittest import mock

import astroid
import platformdirs
import pytest
from astroid import nodes
Expand Down Expand Up @@ -1053,7 +1054,9 @@ def test_finds_pyi_file() -> None:
exit=False,
)
assert run.linter.current_file is not None
assert run.linter.current_file.endswith("foo.pyi")
assert run.linter.current_file.endswith(
"a_module_that_we_definitely_dont_use_in_the_functional_tests.pyi"
)


def test_recursive_finds_pyi_file() -> None:
Expand All @@ -1068,7 +1071,9 @@ def test_recursive_finds_pyi_file() -> None:
exit=False,
)
assert run.linter.current_file is not None
assert run.linter.current_file.endswith("foo.pyi")
assert run.linter.current_file.endswith(
"a_module_that_we_definitely_dont_use_in_the_functional_tests.pyi"
)


def test_no_false_positive_from_pyi_stub() -> None:
Expand Down Expand Up @@ -1126,6 +1131,9 @@ def test_recursive_ignore(ignore_parameter: str, ignore_parameter_value: str) ->
):
module = os.path.abspath(join(REGRTEST_DATA_DIR, *regrtest_data_module))
assert module in linted_file_paths
# We lint the modules in `regrtest` in other tests as well. Prevent test pollution by
# explicitly clearing the astroid caches.
astroid.MANAGER.clear_cache()


def test_source_roots_globbing() -> None:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This module is named in a particular way to prevent test pollution. It was previously named 'foo' and
# all mentions of 'foo' were wrongly resolved to this stub file.
foo = 1

def three_item_iterable(): ...
4 changes: 0 additions & 4 deletions tests/regrtest_data/pyi/foo.pyi

This file was deleted.

2 changes: 1 addition & 1 deletion tests/regrtest_data/uses_module_with_stub.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""If the stub is preferred over the .py, this might emit not-an-iterable"""
from pyi.foo import three_item_iterable
from pyi.a_module_that_we_definitely_dont_use_in_the_functional_tests import three_item_iterable

for val in three_item_iterable():
print(val)

0 comments on commit ba33325

Please sign in to comment.