Skip to content

Commit

Permalink
fix #6341 - disallow session/config in Node.from_parent
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Dec 31, 2019
1 parent 466bbbf commit 4fcacde
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog/6341.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disallow passing session/config to Node.from_parent.
1 change: 1 addition & 0 deletions changelog/6387.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable the usage of super().from_parent for Node subclasses.
2 changes: 1 addition & 1 deletion src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def __init__(self, name, parent, runner=None, dtest=None):

@classmethod
def from_parent(cls, parent, *, name, runner, dtest):
return cls._create(name=name, parent=parent, runner=runner, dtest=dtest)
return super().from_parent(name=name, parent=parent, runner=runner, dtest=dtest)

def setup(self):
if self.dtest is not None:
Expand Down
8 changes: 5 additions & 3 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ def __init__(
self._nodeid += "::" + self.name

@classmethod
def from_parent(cls, parent, *, name):
return cls._create(parent=parent, name=name)
def from_parent(cls, parent, **kw):
assert "config" not in kw
assert "session" not in kw
return cls._create(parent=parent, **kw)

@property
def ihook(self):
Expand Down Expand Up @@ -434,7 +436,7 @@ def __init__(

@classmethod
def from_parent(cls, parent, *, fspath):
return cls._create(parent=parent, fspath=fspath)
return super().from_parent(parent=parent, fspath=fspath)


class File(FSCollector):
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class Class(PyCollector):

@classmethod
def from_parent(cls, parent, *, name, obj=None):
return cls._create(name=name, parent=parent)
return super().from_parent(name=name, parent=parent)

def collect(self):
if not safe_getattr(self.obj, "__test__", True):
Expand Down Expand Up @@ -1459,7 +1459,7 @@ def __init__(

@classmethod
def from_parent(cls, parent, **kw):
return cls._create(parent=parent, **kw)
return super().from_parent(parent=parent, **kw)

def _initrequest(self):
self.funcargs = {}
Expand Down
2 changes: 1 addition & 1 deletion testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def make_function(testdir, **kwargs):
session = testdir.Session.from_config(config)
session._fixturemanager = FixtureManager(session)

return pytest.Function.from_parent(config=config, parent=session, **kwargs)
return pytest.Function.from_parent(parent=session, **kwargs)

def test_function_equality(self, testdir, tmpdir):
def func1():
Expand Down

0 comments on commit 4fcacde

Please sign in to comment.