Skip to content

Commit b68fa9f

Browse files
David Fritzschedavidfritzsche
David Fritzsche
authored andcommitted
Add support for pytest 7.0.x and require Python >= 3.7
1 parent f2e9f14 commit b68fa9f

File tree

5 files changed

+79
-26
lines changed

5 files changed

+79
-26
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,20 @@ decorators are extracted from the ast.
9090
-U -r requirements.txt`.
9191
* Start developing.
9292
* To run all tests with [tox](https://tox.readthedocs.io/en/latest/),
93-
Python 3.6, 3.7 and 3.8 must be available. You might want to look
93+
Python 3.7, 3.8, 3.9 and 3.10 must be available. You might want to look
9494
into using [pyenv](https://github.com/pyenv/pyenv).
9595

9696

9797
# Changelog
9898

99+
## v0.0.9
100+
101+
* Disable soft error limit (#21)
102+
103+
## v0.0.8
104+
105+
* Normalize messages to enable support for mypy 0.902 and pytest 6.2.4 (#20)
106+
99107
## v0.0.7
100108

101109
* Fix `PYTEST_VERSION_INFO` - by [@blueyed](https://github.com/blueyed) (#8)

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ classifiers = [
1818
"Operating System :: Microsoft :: Windows",
1919
"Operating System :: OS Independent",
2020
"Operating System :: POSIX",
21-
"Programming Language :: Python :: 3.6",
2221
"Programming Language :: Python :: 3.7",
2322
"Programming Language :: Python :: 3.8",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
2425
"Typing :: Typed",
2526
]
2627
description-file = "README.md"
2728
dist-name = "pytest-mypy-testing"
2829
home-page = "https://github.com/davidfritzsche/pytest-mypy-testing"
2930
license = "Apache-2.0 OR MIT"
3031
requires = [
31-
"pytest",
32+
"pytest<8",
3233
"mypy",
3334
]
34-
requires-python = ">=3.6"
35+
requires-python = ">=3.7"
3536

3637
[tool.flit.entrypoints.pytest11]
3738
mypy-testing = "pytest_mypy_testing.plugin"

src/pytest_mypy_testing/plugin.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ def __init__(
4343
*,
4444
mypy_item: MypyTestItem,
4545
config: Optional[Config] = None,
46+
**kwargs,
4647
) -> None:
4748
if config is None:
4849
config = parent.config
49-
super().__init__(name, parent=parent, config=config)
50+
super().__init__(name, parent=parent, config=config, **kwargs)
5051
self.add_marker("mypy")
5152
self.mypy_item = mypy_item
5253
for mark in self.mypy_item.marks:
@@ -103,22 +104,37 @@ def repr_failure(self, excinfo, style=None):
103104

104105
class PytestMypyFile(pytest.File):
105106
def __init__(
106-
self, fspath: LocalPath, parent=None, config=None, session=None, nodeid=None
107+
self,
108+
*,
109+
parent=None,
110+
config=None,
111+
session=None,
112+
nodeid=None,
113+
**kwargs,
107114
) -> None:
108115
if config is None:
109116
config = getattr(parent, "config", None)
110-
super().__init__(fspath, parent, config, session, nodeid)
117+
super().__init__(
118+
parent=parent,
119+
config=config,
120+
session=session,
121+
nodeid=nodeid,
122+
**kwargs,
123+
)
111124
self.add_marker("mypy")
112-
self.mypy_file = parse_file(self.fspath, config=config)
125+
if PYTEST_VERSION_INFO >= (7,):
126+
self.mypy_file = parse_file(self.path, config=config)
127+
else:
128+
self.mypy_file = parse_file(self.fspath, config=config)
113129
self._mypy_result: Optional[MypyResult] = None
114130

115131
@classmethod
116-
def from_parent(cls, parent, fspath):
132+
def from_parent(cls, parent, **kwargs):
117133
if PYTEST_VERSION_INFO < (5, 4):
118134
config = getattr(parent, "config", None)
119-
return cls(parent=parent, config=config, fspath=fspath)
135+
return cls(parent=parent, config=config, **kwargs)
120136
else:
121-
return super().from_parent(parent=parent, fspath=fspath)
137+
return super().from_parent(parent=parent, **kwargs)
122138

123139
def collect(self) -> Iterator[PytestMypyTestItem]:
124140
for item in self.mypy_file.items:
@@ -195,12 +211,23 @@ def _run_mypy(self, filename: str) -> MypyResult:
195211
)
196212

197213

198-
def pytest_collect_file(path: LocalPath, parent):
199-
if path.ext == ".mypy-testing" or _is_pytest_test_file(path, parent):
200-
file = PytestMypyFile.from_parent(parent=parent, fspath=path)
201-
if file.mypy_file.items:
202-
return file
203-
return None
214+
if PYTEST_VERSION_INFO < (7,):
215+
216+
def pytest_collect_file(path: LocalPath, parent):
217+
if path.ext == ".mypy-testing" or _is_pytest_test_file(path, parent):
218+
file = PytestMypyFile.from_parent(parent=parent, fspath=path)
219+
if file.mypy_file.items:
220+
return file
221+
return None
222+
223+
else:
224+
225+
def pytest_collect_file(file_path, path: LocalPath, parent): # type: ignore
226+
if path.ext == ".mypy-testing" or _is_pytest_test_file(path, parent):
227+
file = PytestMypyFile.from_parent(parent=parent, path=file_path)
228+
if file.mypy_file.items:
229+
return file
230+
return None
204231

205232

206233
def _is_pytest_test_file(path: LocalPath, parent):

tests/test_plugin.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: David Fritzsche
22
# SPDX-License-Identifier: CC0-1.0
33

4+
import pathlib
45
from types import SimpleNamespace
56
from unittest.mock import Mock
67

@@ -18,11 +19,22 @@
1819
from pytest_mypy_testing.strutil import dedent
1920

2021

22+
PYTEST_VERSION = pytest.__version__
23+
PYTEST_VERSION_INFO = tuple(int(part) for part in PYTEST_VERSION.split(".")[:3])
24+
25+
2126
ERROR = Severity.ERROR
2227
NOTE = Severity.NOTE
2328
WARNING = Severity.WARNING
2429

2530

31+
def call_pytest_collect_file(fspath, parent):
32+
if PYTEST_VERSION_INFO < (7,):
33+
return pytest_collect_file(fspath, parent)
34+
else:
35+
return pytest_collect_file(pathlib.Path(str(fspath)), fspath, parent) # type: ignore
36+
37+
2638
def test_create_mypy_assertion_error():
2739
MypyAssertionError(None, [])
2840

@@ -34,6 +46,7 @@ def mk_dummy_parent(tmp_path, filename, content=""):
3446

3547
config = Mock(spec=Config)
3648
config.rootdir = str(tmp_path)
49+
config.rootpath = str(tmp_path)
3750
config.getini.return_value = ["test_*.py", "*_test.py"]
3851
session = SimpleNamespace(
3952
config=config, isinitpath=lambda p: True, _initialpaths=[]
@@ -43,7 +56,7 @@ def mk_dummy_parent(tmp_path, filename, content=""):
4356
session=session,
4457
nodeid="dummy",
4558
fspath=LocalPath(path),
46-
_path=path,
59+
path=path,
4760
)
4861

4962
return parent
@@ -52,8 +65,9 @@ def mk_dummy_parent(tmp_path, filename, content=""):
5265
@pytest.mark.parametrize("filename", ["z.py", "test_z.mypy-testing"])
5366
def test_pytest_collect_file_not_test_file_name(tmp_path, filename: str):
5467
parent = mk_dummy_parent(tmp_path, filename)
55-
56-
assert pytest_collect_file(parent.fspath, parent) is None
68+
fspath = parent.fspath
69+
actual = call_pytest_collect_file(fspath, parent)
70+
assert actual is None
5771

5872

5973
@pytest.mark.parametrize("filename", ["test_z.py", "test_z.mypy-testing"])
@@ -68,10 +82,11 @@ def foo():
6882

6983
parent = mk_dummy_parent(tmp_path, filename, content)
7084
expected = MypyTestFile(
71-
filename=str(parent._path), source_lines=content.splitlines()
85+
filename=str(parent.path), source_lines=content.splitlines()
7286
)
7387

74-
actual = pytest_collect_file(parent.fspath, parent)
88+
fspath = parent.fspath
89+
actual = call_pytest_collect_file(fspath, parent)
7590
assert isinstance(actual, PytestMypyFile)
7691

7792
assert len(actual.mypy_file.items) == 1

tox.ini

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[tox]
44
isolated_build = True
55
envlist =
6-
{py37,py38,py39}-pytest{60,61,62}-mypy{0910,0921,0930}
7-
{py310}-pytest{62}-mypy{0910,0921,0930}
8-
py-pytest{60,61,62}-mypy{0921,0930}
6+
{py37,py38,py39}-pytest{60,61,62,70}-mypy{0910,0921,0931}
7+
{py310}-pytest{62,70}-mypy{0910,0921,0931}
8+
py-pytest{60,61,62,70}-mypy{0921,0931}
99
linting
1010

1111
[testenv]
@@ -17,16 +17,18 @@ deps =
1717
pytest60: pytest~=6.0.2
1818
pytest61: pytest~=6.1.2
1919
pytest62: pytest~=6.2.5
20+
pytest70: pytest~=7.0.1
2021
pytest-cov
2122
pytest-html
2223
mypy0902: mypy==0.902
2324
mypy0910: mypy==0.910
2425
mypy0921: mypy==0.921
25-
mypy0930: mypy==0.930
26+
mypy0931: mypy==0.931
2627
setenv =
2728
COVERAGE_FILE={toxinidir}/build/{envname}/coverage
2829
commands =
2930
coverage run --context "{envname}" -m pytest \
31+
{posargs} \
3032
--html={toxinidir}/build/{envname}/pytest-report.html \
3133
--junitxml={toxinidir}/build/{envname}/junit.xml
3234

0 commit comments

Comments
 (0)