Skip to content

Commit f1c02f3

Browse files
committed
Switch to from_parent to remove deprecation warning.
Signed-off-by: Chris Lalancette <[email protected]>
1 parent 20d5f06 commit f1c02f3

File tree

1 file changed

+14
-1
lines changed
  • launch_testing/launch_testing/pytest

1 file changed

+14
-1
lines changed

launch_testing/launch_testing/pytest/hooks.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ def reportinfo(self):
123123

124124
class LaunchTestModule(pytest.File):
125125

126+
def __init__(self, parent, *, fspath):
127+
super().__init__(parent=parent, fspath=fspath)
128+
129+
@classmethod
130+
def from_parent(cls, parent, *, fspath):
131+
"""Override from_parent for compatibility."""
132+
# pytest.File.from_parent didn't exist before pytest 5.4
133+
if hasattr(super(), 'from_parent'):
134+
instance = getattr(super(), 'from_parent')(parent=parent, fspath=fspath)
135+
else:
136+
instance = cls(parent=parent, fspath=fspath)
137+
return instance
138+
126139
def makeitem(self, *args, **kwargs):
127140
return LaunchTestItem.from_parent(*args, **kwargs)
128141

@@ -171,7 +184,7 @@ def pytest_pycollect_makemodule(path, parent):
171184
def pytest_launch_collect_makemodule(path, parent, entrypoint):
172185
marks = getattr(entrypoint, 'pytestmark', [])
173186
if marks and any(m.name == 'launch_test' for m in marks):
174-
return LaunchTestModule(path, parent)
187+
return LaunchTestModule.from_parent(parent, fspath=path)
175188

176189

177190
def pytest_addhooks(pluginmanager):

0 commit comments

Comments
 (0)