Skip to content

Commit ba33325

Browse files
dependabot[bot]Pierre-SassoulasDanielNoord
authored
Update pytest requirement from ~=7.4 to ~=8.2 (#9576)
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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
1 parent a94105e commit ba33325

9 files changed

+34
-35
lines changed

pylint/testutils/configuration_test.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import unittest
1313
from pathlib import Path
1414
from typing import Any, Dict
15-
from unittest.mock import Mock
1615

1716
from pylint.lint import Run
1817

@@ -135,18 +134,15 @@ def get_expected_output(
135134

136135
def run_using_a_configuration_file(
137136
configuration_path: Path | str, file_to_lint: str = __file__
138-
) -> tuple[Mock, Mock, Run]:
137+
) -> Run:
139138
"""Simulate a run with a configuration without really launching the checks."""
140139
configuration_path = str(configuration_path)
141140
args = ["--rcfile", configuration_path, file_to_lint]
142-
# We do not capture the `SystemExit` as then the `runner` variable
143-
# would not be accessible outside the `with` block.
144-
with unittest.mock.patch("sys.exit") as mocked_exit:
145-
# Do not actually run checks, that could be slow. We don't mock
146-
# `PyLinter.check`: it calls `PyLinter.initialize` which is
147-
# needed to properly set up messages inclusion/exclusion
148-
# in `_msg_states`, used by `is_message_enabled`.
149-
check = "pylint.lint.pylinter.check_parallel"
150-
with unittest.mock.patch(check) as mocked_check_parallel:
151-
runner = Run(args)
152-
return mocked_exit, mocked_check_parallel, runner
141+
# Do not actually run checks, that could be slow. We don't mock
142+
# `PyLinter.check`: it calls `PyLinter.initialize` which is
143+
# needed to properly set up messages inclusion/exclusion
144+
# in `_msg_states`, used by `is_message_enabled`.
145+
check = "pylint.lint.pylinter.check_parallel"
146+
with unittest.mock.patch(check):
147+
runner = Run(args, exit=False)
148+
return runner

requirements_test_min.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
astroid==3.2.2 # Pinned to a specific version for tests
44
typing-extensions~=4.12
55
py~=1.11.0
6-
pytest~=7.4
6+
pytest~=8.2
77
pytest-benchmark~=4.0
88
pytest-timeout~=2.3
99
towncrier~=23.11

tests/config/test_config.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ def test_can_read_toml_env_variable(tmp_path: Path, file_to_lint_path: str) -> N
5555
)
5656
env_var = "tmp_path_env"
5757
os.environ[env_var] = str(config_file)
58-
mock_exit, _, runner = run_using_a_configuration_file(
59-
f"${env_var}", file_to_lint_path
60-
)
61-
mock_exit.assert_called_once_with(0)
58+
runner = run_using_a_configuration_file(f"${env_var}", file_to_lint_path)
59+
assert runner.linter.msg_status == 0
6260
check_configuration_file_reader(runner)
6361

6462

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

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

242-
_, _, toml_runner = run_using_a_configuration_file(
240+
toml_runner = run_using_a_configuration_file(
243241
HERE
244242
/ "functional"
245243
/ "toml"

tests/config/test_functional_config_loading.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ def default_configuration(
5757
) -> PylintConfiguration:
5858
empty_pylintrc = tmp_path / "pylintrc"
5959
empty_pylintrc.write_text("")
60-
mock_exit, _, runner = run_using_a_configuration_file(
61-
str(empty_pylintrc), file_to_lint_path
62-
)
63-
mock_exit.assert_called_once_with(0)
60+
runner = run_using_a_configuration_file(str(empty_pylintrc), file_to_lint_path)
61+
assert runner.linter.msg_status == 0
6462
return runner.linter.config.__dict__
6563

6664

@@ -88,10 +86,8 @@ def test_functional_config_loading(
8886
warnings.filterwarnings(
8987
"ignore", message="The use of 'MASTER'.*", category=UserWarning
9088
)
91-
mock_exit, _, runner = run_using_a_configuration_file(
92-
configuration_path, file_to_lint_path
93-
)
94-
mock_exit.assert_called_once_with(expected_code)
89+
runner = run_using_a_configuration_file(configuration_path, file_to_lint_path)
90+
assert runner.linter.msg_status == expected_code
9591
out, err = capsys.readouterr()
9692
# 'rstrip()' applied, so we can have a final newline in the expected test file
9793
assert expected_output.rstrip() == out.rstrip(), msg

tests/lint/unittest_lint.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from shutil import copy, rmtree
2121
from unittest import mock
2222

23+
import astroid
2324
import platformdirs
2425
import pytest
2526
from astroid import nodes
@@ -1053,7 +1054,9 @@ def test_finds_pyi_file() -> None:
10531054
exit=False,
10541055
)
10551056
assert run.linter.current_file is not None
1056-
assert run.linter.current_file.endswith("foo.pyi")
1057+
assert run.linter.current_file.endswith(
1058+
"a_module_that_we_definitely_dont_use_in_the_functional_tests.pyi"
1059+
)
10571060

10581061

10591062
def test_recursive_finds_pyi_file() -> None:
@@ -1068,7 +1071,9 @@ def test_recursive_finds_pyi_file() -> None:
10681071
exit=False,
10691072
)
10701073
assert run.linter.current_file is not None
1071-
assert run.linter.current_file.endswith("foo.pyi")
1074+
assert run.linter.current_file.endswith(
1075+
"a_module_that_we_definitely_dont_use_in_the_functional_tests.pyi"
1076+
)
10721077

10731078

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

11301138

11311139
def test_source_roots_globbing() -> None:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This module is named in a particular way to prevent test pollution. It was previously named 'foo' and
2+
# all mentions of 'foo' were wrongly resolved to this stub file.
3+
foo = 1
4+
5+
def three_item_iterable(): ...

tests/regrtest_data/pyi/foo.pyi

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""If the stub is preferred over the .py, this might emit not-an-iterable"""
2-
from pyi.foo import three_item_iterable
2+
from pyi.a_module_that_we_definitely_dont_use_in_the_functional_tests import three_item_iterable
33

44
for val in three_item_iterable():
55
print(val)

0 commit comments

Comments
 (0)