diff --git a/changelog.md b/changelog.md index c778578..c5ff2b6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## [0.9.1](https://github.com/dbader/pytest-mypy/milestone/17) +* Add support for pytest 7. + ## [0.9.0](https://github.com/dbader/pytest-mypy/milestone/14) * Drop support for pytest<4.6. * Add --mypy-config-file. diff --git a/setup.py b/setup.py index 6583611..6680643 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,8 @@ def read(fname): install_requires=[ "attrs>=19.0", "filelock>=3.0", - 'pytest>=4.6; python_version>="3.5" and python_version<"3.10"', + 'pytest>=4.6,<7.0; python_version>="3.5" and python_version<"3.6"', + 'pytest>=4.6; python_version>="3.6" and python_version<"3.10"', 'pytest>=6.2; python_version>="3.10"', 'mypy>=0.500; python_version<"3.8"', 'mypy>=0.700; python_version>="3.8" and python_version<"3.9"', diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index 438d11f..862b097 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -2,6 +2,7 @@ import json import os +from pathlib import Path from tempfile import NamedTemporaryFile from typing import Dict, List, Optional, TextIO @@ -11,6 +12,7 @@ import pytest # type: ignore +PYTEST_MAJOR_VERSION = int(pytest.__version__.partition(".")[0]) mypy_argv = [] nodeid_name = "mypy" @@ -105,9 +107,9 @@ def pytest_configure_node(self, node): # xdist hook mypy_argv.append("--config-file={}".format(mypy_config_file)) -def pytest_collect_file(path, parent): +def pytest_collect_file(file_path, parent): """Create a MypyFileItem for every file mypy should run on.""" - if path.ext in {".py", ".pyi"} and any( + if file_path.suffix in {".py", ".pyi"} and any( [ parent.config.option.mypy, parent.config.option.mypy_config_file, @@ -117,11 +119,23 @@ def pytest_collect_file(path, parent): # Do not create MypyFile instance for a .py file if a # .pyi file with the same name already exists; # pytest will complain about duplicate modules otherwise - if path.ext == ".pyi" or not path.new(ext=".pyi").isfile(): - return MypyFile.from_parent(parent=parent, fspath=path) + if file_path.suffix == ".pyi" or not file_path.with_suffix(".pyi").is_file(): + return MypyFile.from_parent(parent=parent, path=file_path) return None +if PYTEST_MAJOR_VERSION < 7: # pragma: no cover + _pytest_collect_file = pytest_collect_file + + def pytest_collect_file(path, parent): # type: ignore + try: + # https://docs.pytest.org/en/7.0.x/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path + return _pytest_collect_file(Path(str(path)), parent) + except TypeError: + # https://docs.pytest.org/en/7.0.x/deprecations.html#fspath-argument-for-node-constructors-replaced-with-pathlib-path + return MypyFile.from_parent(parent=parent, fspath=path) + + class MypyFile(pytest.File): """A File that Mypy will run on.""" diff --git a/tox.ini b/tox.ini index 0fbf5a7..71fa95b 100644 --- a/tox.ini +++ b/tox.ini @@ -4,22 +4,22 @@ minversion = 3.20 isolated_build = true envlist = 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} - 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} - 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} - 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} - 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} - py310-pytest{6.2, 6.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x} + 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} + 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} + 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} + 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} + py310-pytest{6.2, 6.x, 7.0, 7.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x} publish static [gh-actions] python = 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} - 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} - 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} - 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 - 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} - 3.10: py310-pytest{6.2, 6.x}-mypy{0.78, 0.7x, 0.80, 0.8x, 0.90, 0.9x} + 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} + 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} + 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 + 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} + 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} [testenv] deps = @@ -29,6 +29,8 @@ deps = pytest6.0: pytest ~= 6.0.0 pytest6.2: pytest ~= 6.2.0 pytest6.x: pytest ~= 6.0 + pytest7.0: pytest ~= 7.0.0 + pytest7.x: pytest ~= 7.0 mypy0.50: mypy >= 0.500, < 0.510 mypy0.51: mypy >= 0.510, < 0.520 mypy0.52: mypy >= 0.520, < 0.530