Skip to content

Commit bb3c446

Browse files
Add a warning in functional test update for bad python versions
1 parent d145f7a commit bb3c446

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

pylint/testutils/functional/find_functional_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_functional_test_files_from_directory(
2222

2323
assert (
2424
len(filenames) <= REASONABLY_DISPLAYABLE_VERTICALLY
25-
), f"{dirpath} contain too much functional tests files."
25+
), f"{dirpath} contains too many functional tests files."
2626

2727
for filename in filenames:
2828
if filename != "__init__.py" and filename.endswith(".py"):

pylint/testutils/functional/lint_module_output_update.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
import csv
55
import os
6+
from typing import Optional
67

8+
from _pytest.config import Config
9+
10+
from pylint.constants import PY38_PLUS
11+
from pylint.testutils.functional.test_file import FunctionalTestFile
712
from pylint.testutils.lint_module_test import LintModuleTest
813

914

@@ -16,6 +21,17 @@ class TestDialect(csv.excel):
1621

1722
csv.register_dialect("test", TestDialect)
1823

24+
def __init__(
25+
self, test_file: FunctionalTestFile, config: Optional[Config] = None
26+
) -> None:
27+
if not PY38_PLUS:
28+
raise RuntimeError(
29+
"You need at least python 3.8 for the functional test updater to work. "
30+
"This is because python 3.8 includes a new AST parser, which amongst others "
31+
"returns the end line and end column of most nodes."
32+
)
33+
super().__init__(test_file, config)
34+
1935
def _check_output_text(self, _, expected_output, actual_output):
2036
if not expected_output and not actual_output:
2137
if os.path.exists(self._test_file.expected_output):

pylint/testutils/functional_test_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717

1818
warnings.warn(
19-
"'pylint.testutils.functional_test_file' will be accessible by"
20-
" the 'pylint.testutils.functional' API in pylint 3.0",
19+
"'pylint.testutils.functional_test_file' will be accessible from"
20+
" the 'pylint.testutils.functional' namespace in pylint 3.0.",
2121
DeprecationWarning,
2222
)

tests/testutils/test_lint_module_output_update.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
from pylint.constants import PY38_PLUS
1011
from pylint.testutils import FunctionalTestFile
1112
from pylint.testutils.functional import LintModuleOutputUpdate
1213

@@ -26,6 +27,15 @@ def inner(base: str) -> Tuple[Path, Path, LintModuleOutputUpdate]:
2627
return inner
2728

2829

30+
@pytest.mark.skipif(PY38_PLUS, reason="Requires python 3.7 or lower")
31+
def test_not_py38(tmp_path: Path) -> None:
32+
with pytest.raises(RuntimeError, match="new, better AST in python 3.8"):
33+
LintModuleOutputUpdate(
34+
test_file=FunctionalTestFile(str(tmp_path), str(tmp_path / "filename.py"))
35+
)
36+
37+
38+
@pytest.mark.skipif(not PY38_PLUS, reason="Requires python 3.8 or superior")
2939
def test_lint_module_output_update_fail_before(
3040
lint_module_fixture: Callable[[str], Tuple[Path, Path, LintModuleOutputUpdate]]
3141
) -> None:
@@ -38,6 +48,7 @@ def test_lint_module_output_update_fail_before(
3848
assert not expected_output_file.exists()
3949

4050

51+
@pytest.mark.skipif(not PY38_PLUS, reason="Requires python 3.8 or superior")
4152
def test_lint_module_output_update_effective(
4253
lint_module_fixture: Callable[[str], Tuple[Path, Path, LintModuleOutputUpdate]]
4354
) -> None:
@@ -52,6 +63,7 @@ def test_lint_module_output_update_effective(
5263
)
5364

5465

66+
@pytest.mark.skipif(not PY38_PLUS, reason="Requires python 3.8 or superior")
5567
def test_lint_module_output_update_remove_useless_txt(
5668
lint_module_fixture: Callable[[str], Tuple[Path, Path, LintModuleOutputUpdate]]
5769
) -> None:

0 commit comments

Comments
 (0)