1 https://github.com/shopkeep/pytest-black/pull/61
3 diff --git a/.travis.yml b/.travis.yml
4 index d9891e3..178b5f6 100644
12 + env: TOX_ENV=py310,flake8
18 @@ -9,8 +13,6 @@ matrix:
27 diff --git a/pytest_black.py b/pytest_black.py
28 index 04c80cb..23b461f 100644
31 @@ -20,13 +20,10 @@ def pytest_addoption(parser):
35 -def pytest_collect_file(path, parent):
36 +def pytest_collect_file(file_path, path, parent):
37 config = parent.config
38 if config.option.black and path.ext == ".py":
39 - if hasattr(BlackItem, "from_parent"):
40 - return BlackItem.from_parent(parent, fspath=path)
42 - return BlackItem(path, parent)
43 + return BlackFile.from_parent(parent, path=file_path)
46 def pytest_configure(config):
47 @@ -42,10 +39,17 @@ def pytest_unconfigure(config):
48 config.cache.set(HISTKEY, config._blackmtimes)
51 -class BlackItem(pytest.Item, pytest.File):
52 - def __init__(self, fspath, parent):
53 - super(BlackItem, self).__init__(fspath, parent)
54 - self._nodeid += "::BLACK"
55 +class BlackFile(pytest.File):
57 + """ returns a list of children (items and collectors)
58 + for this collection node.
60 + yield BlackItem.from_parent(self, name="black")
63 +class BlackItem(pytest.Item):
64 + def __init__(self, **kwargs):
65 + super(BlackItem, self).__init__(**kwargs)
66 self.add_marker("black")
68 with open("pyproject.toml") as toml_file:
69 @@ -61,8 +65,8 @@ def __init__(self, fspath, parent):
71 pytest.importorskip("black")
72 mtimes = getattr(self.config, "_blackmtimes", {})
73 - self._blackmtime = self.fspath.mtime()
74 - old = mtimes.get(str(self.fspath), 0)
75 + self._blackmtime = self.path.stat().st_mtime
76 + old = mtimes.get(str(self.path), 0)
77 if self._blackmtime == old:
78 pytest.skip("file(s) previously passed black format checks")
80 @@ -70,7 +74,7 @@ def setup(self):
81 pytest.skip("file(s) excluded by pyproject.toml")
84 - cmd = [sys.executable, "-m", "black", "--check", "--diff", "--quiet", str(self.fspath)]
85 + cmd = [sys.executable, "-m", "black", "--check", "--diff", "--quiet", str(self.path)]
88 cmd, check=True, stdout=subprocess.PIPE, universal_newlines=True
89 @@ -79,7 +83,7 @@ def runtest(self):
92 mtimes = getattr(self.config, "_blackmtimes", {})
93 - mtimes[str(self.fspath)] = self._blackmtime
94 + mtimes[str(self.path)] = self._blackmtime
96 def repr_failure(self, excinfo):
97 if excinfo.errisinstance(BlackError):
98 @@ -87,7 +91,7 @@ def repr_failure(self, excinfo):
99 return super(BlackItem, self).repr_failure(excinfo)
101 def reportinfo(self):
102 - return (self.fspath, -1, "Black format check")
103 + return (self.path, -1, "Black format check")
105 def _skip_test(self):
106 return self._excluded() or (not self._included())
107 @@ -95,24 +99,18 @@ def _skip_test(self):
109 if "include" not in self.pyproject:
111 - return re.search(self.pyproject["include"], str(self.fspath))
112 + return re.search(self.pyproject["include"], str(self.path))
115 if "exclude" not in self.pyproject:
117 - return re.search(self.pyproject["exclude"], str(self.fspath))
118 + return re.search(self.pyproject["exclude"], str(self.path))
120 def _re_fix_verbose(self, regex):
122 regex = "(?x)" + regex
123 return re.compile(regex)
126 - """ returns a list of children (items and collectors)
127 - for this collection node.
132 class BlackError(Exception):
134 diff --git a/setup.py b/setup.py
135 index 88784dd..576a9f7 100644
138 @@ -23,9 +23,9 @@ def read(fname):
139 long_description=read("README.md"),
140 long_description_content_type="text/markdown",
141 py_modules=["pytest_black"],
142 - python_requires=">=2.7",
143 + python_requires=">=3.5",
147 # Minimum requirement on black 19.3b0 or later is not declared here as
148 # workaround for https://github.com/pypa/pipenv/issues/3928
149 'black; python_version >= "3.6"',
150 @@ -38,7 +38,6 @@ def read(fname):
151 "Framework :: Pytest",
152 "Intended Audience :: Developers",
153 "Topic :: Software Development :: Testing",
154 - "Programming Language :: Python :: 2.7",
155 "Programming Language :: Python :: 3",
156 "Operating System :: OS Independent",
157 "License :: OSI Approved :: MIT License",
158 diff --git a/tox.ini b/tox.ini
159 index 06711c2..0134ae4 100644
166 -envlist = py27,py35,py36,py37,py38,flake8
167 +envlist = py35,py36,py37,py38,py39,py310,flake8
172 commands = pytest {posargs:tests}