Skip to content

Commit 2c19b98

Browse files
hroncokjgraham
authored andcommitted
Use Node.from_parent() constructor to support pytest 6
Add a wrapper not to break pytest 4 (needed for Python 2 support). ============================= test session starts ============================== platform linux -- Python 3.9.0b5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 rootdir: /builddir/build/BUILD/html5lib-1.1, configfile: pytest.ini plugins: expect-1.1.0 collected 0 items / 1 error ==================================== ERRORS ==================================== ________________________ ERROR collecting test session _________________________ /usr/lib/python3.9/site-packages/pluggy/hooks.py:286: in __call__ return self._hookexec(self, self.get_hookimpls(), kwargs) /usr/lib/python3.9/site-packages/pluggy/manager.py:93: in _hookexec return self._inner_hookexec(hook, methods, kwargs) /usr/lib/python3.9/site-packages/pluggy/manager.py:84: in <lambda> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( html5lib/tests/conftest.py:105: in pytest_collect_file return TokenizerFile(path, parent) /usr/lib/python3.9/site-packages/_pytest/nodes.py:95: in __call__ warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=2) E pytest.PytestDeprecationWarning: Direct construction of TokenizerFile has been deprecated, please use TokenizerFile.from_parent. E See https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent for more details. Fixes html5lib#505
1 parent a7c1887 commit 2c19b98

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

html5lib/tests/conftest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,19 @@ def pytest_collect_file(path, parent):
9999

100100
if _tree_construction in dir_and_parents:
101101
if path.ext == ".dat":
102-
return TreeConstructionFile(path, parent)
102+
return TreeConstructionFile.from_parent(parent, fspath=path)
103103
elif _tokenizer in dir_and_parents:
104104
if path.ext == ".test":
105-
return TokenizerFile(path, parent)
105+
return TokenizerFile.from_parent(parent, fspath=path)
106106
elif _sanitizer_testdata in dir_and_parents:
107107
if path.ext == ".dat":
108-
return SanitizerFile(path, parent)
108+
return SanitizerFile.from_parent(parent, fspath=path)
109+
110+
111+
# Tiny wrapper to allow .from_parent constructors on older pytest for PY27
112+
if not hasattr(pytest.Item.__base__, "from_parent"):
113+
@classmethod
114+
def from_parent(cls, parent, **kwargs):
115+
return cls(parent=parent, **kwargs)
116+
117+
pytest.Item.__base__.from_parent = from_parent

html5lib/tests/sanitizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def collect(self):
1313
with codecs.open(str(self.fspath), "r", encoding="utf-8") as fp:
1414
tests = json.load(fp)
1515
for i, test in enumerate(tests):
16-
yield SanitizerTest(str(i), self, test=test)
16+
yield SanitizerTest.from_parent(self, name=str(i), test=test)
1717

1818

1919
class SanitizerTest(pytest.Item):

html5lib/tests/tokenizer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def collect(self):
192192
tests = json.load(fp)
193193
if 'tests' in tests:
194194
for i, test in enumerate(tests['tests']):
195-
yield TokenizerTestCollector(str(i), self, testdata=test)
195+
yield TokenizerTestCollector.from_parent(self, name=str(i), testdata=test)
196196

197197

198198
class TokenizerTestCollector(pytest.Collector):
@@ -207,10 +207,10 @@ def __init__(self, name, parent=None, config=None, session=None, testdata=None):
207207
def collect(self):
208208
for initialState in self.testdata["initialStates"]:
209209
initialState = capitalize(initialState)
210-
item = TokenizerTest(initialState,
211-
self,
212-
self.testdata,
213-
initialState)
210+
item = TokenizerTest.from_parent(self,
211+
name=initialState,
212+
test=self.testdata,
213+
initialState=initialState)
214214
if self.testdata["input"] is None:
215215
item.add_marker(pytest.mark.skipif(True, reason="Relies on lone surrogates"))
216216
yield item

html5lib/tests/tree_construction.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TreeConstructionFile(pytest.File):
2626
def collect(self):
2727
tests = TestData(str(self.fspath), "data")
2828
for i, test in enumerate(tests):
29-
yield TreeConstructionTest(str(i), self, testdata=test)
29+
yield TreeConstructionTest.from_parent(self, name=str(i), testdata=test)
3030

3131

3232
class TreeConstructionTest(pytest.Collector):
@@ -48,11 +48,11 @@ def _getParserTests(self, treeName, treeAPIs):
4848
nodeid = "%s::parser::namespaced" % treeName
4949
else:
5050
nodeid = "%s::parser::void-namespace" % treeName
51-
item = ParserTest(nodeid,
52-
self,
53-
self.testdata,
54-
treeAPIs["builder"] if treeAPIs is not None else None,
55-
namespaceHTMLElements)
51+
item = ParserTest.from_parent(self,
52+
name=nodeid,
53+
test=self.testdata,
54+
treeClass=treeAPIs["builder"] if treeAPIs is not None else None,
55+
namespaceHTMLElements=namespaceHTMLElements)
5656
item.add_marker(getattr(pytest.mark, treeName))
5757
item.add_marker(pytest.mark.parser)
5858
if namespaceHTMLElements:
@@ -61,10 +61,10 @@ def _getParserTests(self, treeName, treeAPIs):
6161

6262
def _getTreeWalkerTests(self, treeName, treeAPIs):
6363
nodeid = "%s::treewalker" % treeName
64-
item = TreeWalkerTest(nodeid,
65-
self,
66-
self.testdata,
67-
treeAPIs)
64+
item = TreeWalkerTest.from_parent(self,
65+
name=nodeid,
66+
test=self.testdata,
67+
treeAPIs=treeAPIs)
6868
item.add_marker(getattr(pytest.mark, treeName))
6969
item.add_marker(pytest.mark.treewalker)
7070
yield item

requirements-test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
tox>=3.15.1,<4
44
flake8>=3.8.1,<3.9
55
pytest>=4.6.10,<5 ; python_version < '3'
6-
pytest>=5.4.2,<6 ; python_version >= '3'
6+
pytest>=5.4.2,<7 ; python_version >= '3'
77
coverage>=5.1,<6
88
pytest-expect>=1.1.0,<2
99
mock>=3.0.5,<4 ; python_version < '3.6'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy