Skip to content

Commit cecc161

Browse files
Bump pytest from 7.4.4 to 8.2.1 in /tools (#46383)
* --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Remove vendored pytest * Squashed 'tools/third_party/pytest/' content from commit 66ff8dffdf9 git-subtree-dir: tools/third_party/pytest git-subtree-split: 66ff8dffdf9eee9b3dd6686de34542c49ff80dcd * Remove unused py library * Update resources tests to work with pytest 8 The single class implementing both a test collector and a test item no longer works; these need to be split into separate classes. * Update pytest_ignore_collect argument for pytest 8 * Update pytest-cov to 5.0.0 * Remove old attrs library * Squashed 'tools/third_party/attrs/' content from commit 9e443b18527 git-subtree-dir: tools/third_party/attrs git-subtree-split: 9e443b18527dc96b194e92805fa751cbf8434ba9 * Remove vendored pluggy * Fix log message formatting * Squashed 'tools/third_party/pluggy/' content from commit f8aa4a00971 git-subtree-dir: tools/third_party/pluggy git-subtree-split: f8aa4a009716a7994f2f6c1947d9fa69feccbdd5 * Add exceptiongroup library for Python < 3.11 * Readd _version.py file for pytest * Reset internal state of Stash class in unit tests * Fix indent in conftest.py --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: James Graham <[email protected]>
1 parent 13861f4 commit cecc161

File tree

700 files changed

+48177
-42102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

700 files changed

+48177
-42102
lines changed

resources/test/conftest.py

+28-31
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ def pytest_collect_file(file_path, path, parent):
4040
return
4141
test_type = test_type.split(os.path.sep)[1]
4242

43-
# Handle the deprecation of Node construction in pytest6
44-
# https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent
45-
if hasattr(HTMLItem, "from_parent"):
46-
return HTMLItem.from_parent(parent, filename=str(file_path), test_type=test_type)
47-
return HTMLItem(parent, str(file_path), test_type)
43+
return HTMLFile.from_parent(parent, path=file_path, test_type=test_type)
4844

4945

5046
def pytest_configure(config):
@@ -144,26 +140,29 @@ def _summarize_status(status_obj):
144140
return summarized
145141

146142

147-
class HTMLItem(pytest.Item, pytest.Collector):
148-
def __init__(self, parent, filename, test_type):
149-
self.url = parent.session.config.server.url(filename)
150-
self.type = test_type
143+
class HTMLFile(pytest.File):
144+
def __init__(self, test_type=None, **kwargs):
145+
super().__init__(**kwargs)
146+
self.test_type = test_type
147+
148+
def collect(self):
149+
url = self.session.config.server.url(self.path)
151150
# Some tests are reliant on the WPT servers substitution functionality,
152151
# so tests must be retrieved from the server rather than read from the
153152
# file system directly.
154-
handle = urllib.request.urlopen(self.url,
155-
context=parent.session.config.ssl_context)
153+
handle = urllib.request.urlopen(url,
154+
context=self.parent.session.config.ssl_context)
156155
try:
157156
markup = handle.read()
158157
finally:
159158
handle.close()
160159

161-
if test_type not in TEST_TYPES:
162-
raise ValueError('Unrecognized test type: "%s"' % test_type)
160+
if self.test_type not in TEST_TYPES:
161+
raise ValueError('Unrecognized test type: "%s"' % self.test_type)
163162

164163
parsed = html5lib.parse(markup, namespaceHTMLElements=False)
165164
name = None
166-
self.expected = None
165+
expected = None
167166

168167
for element in parsed.iter():
169168
if not name and element.tag == 'title':
@@ -172,39 +171,37 @@ def __init__(self, parent, filename, test_type):
172171
if element.tag == 'script':
173172
if element.attrib.get('id') == 'expected':
174173
try:
175-
self.expected = json.loads(element.text)
174+
expected = json.loads(element.text)
176175
except ValueError:
177176
print("Failed parsing JSON in %s" % filename)
178177
raise
179178

180179
if not name:
181180
raise ValueError('No name found in %s add a <title> element' % filename)
182-
elif self.type == 'functional':
183-
if not self.expected:
181+
elif self.test_type == 'functional':
182+
if not expected:
184183
raise ValueError('Functional tests must specify expected report data')
185-
elif self.type == 'unit' and self.expected:
184+
elif self.test_type == 'unit' and expected:
186185
raise ValueError('Unit tests must not specify expected report data')
187186

188-
# Ensure that distinct items have distinct fspath attributes.
189-
# This is necessary because pytest has an internal cache keyed on it,
190-
# and only the first test with any given fspath will be run.
191-
#
192-
# This cannot use super(HTMLItem, self).__init__(..) because only the
193-
# Collector constructor takes the fspath argument.
194-
pytest.Item.__init__(self, name, parent)
195-
pytest.Collector.__init__(self, name, parent, fspath=py.path.local(filename))
187+
yield HTMLItem.from_parent(self, name=name, url=url, expected=expected)
188+
196189

190+
class HTMLItem(pytest.Item):
191+
def __init__(self, name, parent=None, config=None, session=None, nodeid=None, test_type=None, url=None, expected=None, **kwargs):
192+
super().__init__(name, parent, config, session, nodeid, **kwargs)
193+
194+
self.test_type = self.parent.test_type
195+
self.url = url
196+
self.expected = expected
197197

198198
def reportinfo(self):
199199
return self.fspath, None, self.url
200200

201-
def repr_failure(self, excinfo):
202-
return pytest.Collector.repr_failure(self, excinfo)
203-
204201
def runtest(self):
205-
if self.type == 'unit':
202+
if self.test_type == 'unit':
206203
self._run_unit_test()
207-
elif self.type == 'functional':
204+
elif self.test_type == 'functional':
208205
self._run_functional_test()
209206
else:
210207
raise NotImplementedError

tools/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"default" if impl != "PyPy" else "pypy"))
1818

1919

20-
def pytest_ignore_collect(collection_path, path, config):
20+
def pytest_ignore_collect(collection_path, config):
2121
# ignore directories which have their own tox.ini
2222
assert collection_path != config.rootpath
2323
if (collection_path / "tox.ini").is_file():

tools/localpaths.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
sys.path.insert(0, os.path.join(here, "third_party", "attrs", "src"))
1212
sys.path.insert(0, os.path.join(here, "third_party", "html5lib"))
1313
sys.path.insert(0, os.path.join(here, "third_party", "zipp"))
14+
sys.path.insert(0, os.path.join(here, "third_party", "exceptiongroup", "src"))
1415
sys.path.insert(0, os.path.join(here, "third_party", "more-itertools"))
1516
sys.path.insert(0, os.path.join(here, "third_party", "packaging"))
1617
sys.path.insert(0, os.path.join(here, "third_party", "pathlib2"))

tools/requirements_pytest.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pytest==7.4.4
2-
pytest-cov==4.1.0
1+
pytest==8.2.1
2+
pytest-cov==5.0.0
33
hypothesis==6.100.2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node: $Format:%H$
2+
node-date: $Format:%cI$
3+
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
4+
ref-names: $Format:%D$
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Force LF line endings for text files
2+
* text=auto eol=lf
3+
4+
# Needed for setuptools-scm-git-archive
5+
.git_archival.txt export-subst

0 commit comments

Comments
 (0)