Skip to content

Commit db5ed42

Browse files
author
Ryan Soklaski
committed
Add pyright tests parameterized over python versions
1 parent cb05529 commit db5ed42

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

whole-repo-tests/test_pyright.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from hypothesistooling.projects.hypothesispython import HYPOTHESIS_PYTHON, PYTHON_SRC
2222
from hypothesistooling.scripts import pip_tool, tool_path
2323

24+
PYTHON_VERSIONS = [f"3.{v}" for v in range(7, 11)]
25+
2426

2527
@pytest.mark.skip(
2628
reason="Hypothesis type-annotates the public API as a convenience for users, "
@@ -30,7 +32,8 @@ def test_pyright_passes_on_hypothesis():
3032
pip_tool("pyright", "--project", HYPOTHESIS_PYTHON)
3133

3234

33-
def test_pyright_passes_on_basic_test(tmp_path: Path):
35+
@pytest.mark.parametrize("python_version", PYTHON_VERSIONS)
36+
def test_pyright_passes_on_basic_test(tmp_path: Path, python_version: str):
3437
file = tmp_path / "test.py"
3538
file.write_text(
3639
textwrap.dedent(
@@ -51,10 +54,40 @@ def test_bar(x: str):
5154
"""
5255
)
5356
)
54-
_write_config(tmp_path, {"typeCheckingMode": "strict"})
57+
_write_config(
58+
tmp_path, {"typeCheckingMode": "strict", "pythonVersion": python_version}
59+
)
5560
assert _get_pyright_errors(file) == []
5661

5762

63+
@pytest.mark.parametrize("python_version", PYTHON_VERSIONS)
64+
def test_given_only_allows_strategies(tmp_path: Path, python_version: str):
65+
file = tmp_path / "test.py"
66+
file.write_text(
67+
textwrap.dedent(
68+
"""
69+
from hypothesis import given
70+
71+
@given(1)
72+
def f():
73+
pass
74+
"""
75+
)
76+
)
77+
_write_config(
78+
tmp_path, {"typeCheckingMode": "strict", "pythonVersion": python_version}
79+
)
80+
assert (
81+
sum(
82+
e["message"].startswith(
83+
'Argument of type "Literal[1]" cannot be assigned to parameter "_given_arguments"'
84+
)
85+
for e in _get_pyright_errors(file)
86+
)
87+
== 1
88+
)
89+
90+
5891
def test_pyright_issue_3296(tmp_path: Path):
5992
file = tmp_path / "test.py"
6093
file.write_text(

0 commit comments

Comments
 (0)