Skip to content

Commit 569cfc9

Browse files
authored
tests: enforce meaningful version checks (#15635)
Follow up to #15430 — would've made #15566 (comment) unnecessary.
1 parent 0a020fa commit 569cfc9

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

mypy/test/data.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,17 @@ def _item_fail(msg: str) -> NoReturn:
167167
version = tuple(int(x) for x in version_str.split("."))
168168
except ValueError:
169169
_item_fail(f"{version_str!r} is not a valid python version")
170-
if version < defaults.PYTHON3_VERSION:
171-
_item_fail(
172-
f"Version check against {version}; must be >= {defaults.PYTHON3_VERSION}"
173-
)
174170
if compare_op == ">=":
171+
if version <= defaults.PYTHON3_VERSION:
172+
_item_fail(
173+
f"{arg} always true since minimum runtime version is {defaults.PYTHON3_VERSION}"
174+
)
175175
version_check = sys.version_info >= version
176176
elif compare_op == "==":
177+
if version < defaults.PYTHON3_VERSION:
178+
_item_fail(
179+
f"{arg} always false since minimum runtime version is {defaults.PYTHON3_VERSION}"
180+
)
177181
if not 1 < len(version) < 4:
178182
_item_fail(
179183
f'Only minor or patch version checks are currently supported with "==": {version_str!r}'

mypy/test/meta/test_parse_data.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,37 @@ def test_parse_invalid_section(self) -> None:
6767
f".test:{expected_lineno}: Invalid section header [unknownsection] in case 'abc'"
6868
)
6969
assert expected in actual
70+
71+
def test_bad_ge_version_check(self) -> None:
72+
# Arrange
73+
data = self._dedent(
74+
"""
75+
[case abc]
76+
s: str
77+
[out version>=3.8]
78+
abc
79+
"""
80+
)
81+
82+
# Act
83+
actual = self._run_pytest(data)
84+
85+
# Assert
86+
assert "version>=3.8 always true since minimum runtime version is (3, 8)" in actual
87+
88+
def test_bad_eq_version_check(self) -> None:
89+
# Arrange
90+
data = self._dedent(
91+
"""
92+
[case abc]
93+
s: str
94+
[out version==3.7]
95+
abc
96+
"""
97+
)
98+
99+
# Act
100+
actual = self._run_pytest(data)
101+
102+
# Assert
103+
assert "version==3.7 always false since minimum runtime version is (3, 8)" in actual

0 commit comments

Comments
 (0)