Skip to content

Commit

Permalink
Merge pull request #132 from dmtucker/pytest7
Browse files Browse the repository at this point in the history
Add support for pytest 7
  • Loading branch information
dmtucker committed Feb 7, 2022
2 parents 518aae9 + 00c7204 commit 3c9d8d5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
Expand Down
22 changes: 18 additions & 4 deletions src/pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Dict, List, Optional, TextIO

Expand All @@ -11,6 +12,7 @@
import pytest # type: ignore


PYTEST_MAJOR_VERSION = int(pytest.__version__.partition(".")[0])
mypy_argv = []
nodeid_name = "mypy"

Expand Down Expand Up @@ -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,
Expand All @@ -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."""
Expand Down
22 changes: 12 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down

0 comments on commit 3c9d8d5

Please sign in to comment.