Skip to content

Commit 3c9d8d5

Browse files
authored
Merge pull request #132 from dmtucker/pytest7
Add support for pytest 7
2 parents 518aae9 + 00c7204 commit 3c9d8d5

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [0.9.1](https://github.com/dbader/pytest-mypy/milestone/17)
4+
* Add support for pytest 7.
5+
36
## [0.9.0](https://github.com/dbader/pytest-mypy/milestone/14)
47
* Drop support for pytest<4.6.
58
* Add --mypy-config-file.

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def read(fname):
3434
install_requires=[
3535
"attrs>=19.0",
3636
"filelock>=3.0",
37-
'pytest>=4.6; python_version>="3.5" and python_version<"3.10"',
37+
'pytest>=4.6,<7.0; python_version>="3.5" and python_version<"3.6"',
38+
'pytest>=4.6; python_version>="3.6" and python_version<"3.10"',
3839
'pytest>=6.2; python_version>="3.10"',
3940
'mypy>=0.500; python_version<"3.8"',
4041
'mypy>=0.700; python_version>="3.8" and python_version<"3.9"',

src/pytest_mypy.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
from pathlib import Path
56
from tempfile import NamedTemporaryFile
67
from typing import Dict, List, Optional, TextIO
78

@@ -11,6 +12,7 @@
1112
import pytest # type: ignore
1213

1314

15+
PYTEST_MAJOR_VERSION = int(pytest.__version__.partition(".")[0])
1416
mypy_argv = []
1517
nodeid_name = "mypy"
1618

@@ -105,9 +107,9 @@ def pytest_configure_node(self, node): # xdist hook
105107
mypy_argv.append("--config-file={}".format(mypy_config_file))
106108

107109

108-
def pytest_collect_file(path, parent):
110+
def pytest_collect_file(file_path, parent):
109111
"""Create a MypyFileItem for every file mypy should run on."""
110-
if path.ext in {".py", ".pyi"} and any(
112+
if file_path.suffix in {".py", ".pyi"} and any(
111113
[
112114
parent.config.option.mypy,
113115
parent.config.option.mypy_config_file,
@@ -117,11 +119,23 @@ def pytest_collect_file(path, parent):
117119
# Do not create MypyFile instance for a .py file if a
118120
# .pyi file with the same name already exists;
119121
# pytest will complain about duplicate modules otherwise
120-
if path.ext == ".pyi" or not path.new(ext=".pyi").isfile():
121-
return MypyFile.from_parent(parent=parent, fspath=path)
122+
if file_path.suffix == ".pyi" or not file_path.with_suffix(".pyi").is_file():
123+
return MypyFile.from_parent(parent=parent, path=file_path)
122124
return None
123125

124126

127+
if PYTEST_MAJOR_VERSION < 7: # pragma: no cover
128+
_pytest_collect_file = pytest_collect_file
129+
130+
def pytest_collect_file(path, parent): # type: ignore
131+
try:
132+
# https://docs.pytest.org/en/7.0.x/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path
133+
return _pytest_collect_file(Path(str(path)), parent)
134+
except TypeError:
135+
# https://docs.pytest.org/en/7.0.x/deprecations.html#fspath-argument-for-node-constructors-replaced-with-pathlib-path
136+
return MypyFile.from_parent(parent=parent, fspath=path)
137+
138+
125139
class MypyFile(pytest.File):
126140

127141
"""A File that Mypy will run on."""

tox.ini

+12-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ minversion = 3.20
44
isolated_build = true
55
envlist =
66
py35-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
7-
py36-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
8-
py37-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
9-
py38-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.71, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
10-
py39-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
11-
py310-pytest{6.2, 6.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
7+
py36-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
8+
py37-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
9+
py38-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{0.71, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
10+
py39-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
11+
py310-pytest{6.2, 6.x, 7.0, 7.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
1212
publish
1313
static
1414

1515
[gh-actions]
1616
python =
1717
3.5: py35-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
18-
3.6: py36-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
19-
3.7: py37-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
20-
3.8: py38-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.71, 0.7x, 0.80, 0.8x, 0.90, 0.9x}, publish, static
21-
3.9: py39-pytest{4.6, 5.0, 5.x, 6.0, 6.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
22-
3.10: py310-pytest{6.2, 6.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
18+
3.6: py36-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
19+
3.7: py37-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{0.50, 0.5x, 0.60, 0.6x, 0.70, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
20+
3.8: py38-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{0.71, 0.7x, 0.80, 0.8x, 0.90, 0.9x}, publish, static
21+
3.9: py39-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
22+
3.10: py310-pytest{6.2, 6.x, 7.0, 7.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x}
2323

2424
[testenv]
2525
deps =
@@ -29,6 +29,8 @@ deps =
2929
pytest6.0: pytest ~= 6.0.0
3030
pytest6.2: pytest ~= 6.2.0
3131
pytest6.x: pytest ~= 6.0
32+
pytest7.0: pytest ~= 7.0.0
33+
pytest7.x: pytest ~= 7.0
3234
mypy0.50: mypy >= 0.500, < 0.510
3335
mypy0.51: mypy >= 0.510, < 0.520
3436
mypy0.52: mypy >= 0.520, < 0.530

0 commit comments

Comments
 (0)