Skip to content

Commit 40c243b

Browse files
authored
Fix showing DeprecationWarnings for functional tests (#7665)
1 parent 43e8171 commit 40c243b

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

tests/test_functional.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import pytest
1313
from _pytest.config import Config
14-
from _pytest.recwarn import WarningsRecorder
1514

1615
from pylint import testutils
1716
from pylint.testutils import UPDATE_FILE, UPDATE_OPTION
@@ -33,34 +32,28 @@
3332
]
3433
TESTS_NAMES = [t.base for t in TESTS]
3534
TEST_WITH_EXPECTED_DEPRECATION = [
35+
"anomalous_backslash_escape",
36+
"anomalous_unicode_escape",
37+
"excess_escapes",
3638
"future_unicode_literals",
37-
"anomalous_unicode_escape_py3",
3839
]
3940

4041

4142
@pytest.mark.parametrize("test_file", TESTS, ids=TESTS_NAMES)
42-
def test_functional(
43-
test_file: FunctionalTestFile, recwarn: WarningsRecorder, pytestconfig: Config
44-
) -> None:
43+
def test_functional(test_file: FunctionalTestFile, pytestconfig: Config) -> None:
4544
__tracebackhide__ = True # pylint: disable=unused-variable
45+
lint_test: LintModuleOutputUpdate | testutils.LintModuleTest
4646
if UPDATE_FILE.exists():
47-
lint_test: (
48-
LintModuleOutputUpdate | testutils.LintModuleTest
49-
) = LintModuleOutputUpdate(test_file, pytestconfig)
47+
lint_test = LintModuleOutputUpdate(test_file, pytestconfig)
5048
else:
5149
lint_test = testutils.LintModuleTest(test_file, pytestconfig)
5250
lint_test.setUp()
53-
lint_test.runTest()
54-
if recwarn.list:
55-
if (
56-
test_file.base in TEST_WITH_EXPECTED_DEPRECATION
57-
and sys.version_info.minor > 5
58-
):
59-
assert any(
60-
"invalid escape sequence" in str(i.message)
61-
for i in recwarn.list
62-
if issubclass(i.category, DeprecationWarning)
63-
)
51+
52+
if test_file.base in TEST_WITH_EXPECTED_DEPRECATION:
53+
with pytest.warns(DeprecationWarning, match="invalid escape sequence"):
54+
lint_test.runTest()
55+
else:
56+
lint_test.runTest()
6457

6558

6659
if __name__ == "__main__":

0 commit comments

Comments
 (0)