From 0d4d8dcad54dac9241e047396d516ca3040d90f3 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Wed, 18 Mar 2020 15:47:11 -0500 Subject: [PATCH 1/3] stop using constructors deprecated in pytest 5.4 (#391) Signed-off-by: Dan Rose Signed-off-by: Shane Loretz --- launch_testing/launch_testing/pytest/hooks.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/launch_testing/launch_testing/pytest/hooks.py b/launch_testing/launch_testing/pytest/hooks.py index 52d39d612..7bc519320 100644 --- a/launch_testing/launch_testing/pytest/hooks.py +++ b/launch_testing/launch_testing/pytest/hooks.py @@ -110,8 +110,18 @@ def pytest_pycollect_makemodule(path, parent): if module is not None: return module if path.basename == '__init__.py': - return pytest.Package(path, parent) - return pytest.Module(path, parent) + try: + # since https://docs.pytest.org/en/latest/changelog.html#deprecations + # todo: remove fallback once all platforms use pytest >=5.4 + return pytest.Package.from_parent(parent, fspath=path) + except AttributeError: + return pytest.Package(path, parent) + try: + # since https://docs.pytest.org/en/latest/changelog.html#deprecations + # todo: remove fallback once all platforms use pytest >=5.4 + return pytest.Module.from_parent(parent, fspath=path) + except AttributeError: + return pytest.Module(path, parent) @pytest.hookimpl(trylast=True) From 5c8981e4a83fdf7ec0d401eb9c789e6c450a5b93 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Wed, 13 May 2020 17:40:31 +0000 Subject: [PATCH 2/3] Switch to from_parent to remove deprecation warning. Signed-off-by: Chris Lalancette Signed-off-by: Shane Loretz --- launch_testing/launch_testing/pytest/hooks.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/launch_testing/launch_testing/pytest/hooks.py b/launch_testing/launch_testing/pytest/hooks.py index 7bc519320..8c90f51f7 100644 --- a/launch_testing/launch_testing/pytest/hooks.py +++ b/launch_testing/launch_testing/pytest/hooks.py @@ -80,6 +80,19 @@ def reportinfo(self): class LaunchTestModule(pytest.File): + def __init__(self, parent, *, fspath): + super().__init__(parent=parent, fspath=fspath) + + @classmethod + def from_parent(cls, parent, *, fspath): + """Override from_parent for compatibility.""" + # pytest.File.from_parent didn't exist before pytest 5.4 + if hasattr(super(), 'from_parent'): + instance = getattr(super(), 'from_parent')(parent=parent, fspath=fspath) + else: + instance = cls(parent=parent, fspath=fspath) + return instance + def makeitem(self, *args, **kwargs): return LaunchTestItem(*args, **kwargs) @@ -128,7 +141,7 @@ def pytest_pycollect_makemodule(path, parent): def pytest_launch_collect_makemodule(path, parent, entrypoint): marks = getattr(entrypoint, 'pytestmark', []) if marks and any(m.name == 'launch_test' for m in marks): - return LaunchTestModule(path, parent) + return LaunchTestModule.from_parent(parent, fspath=path) def pytest_addhooks(pluginmanager): From a790417ad02af15486c8a4c460d855a59b2ed1a3 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Thu, 16 Apr 2020 13:17:38 -0700 Subject: [PATCH 3/3] avoid deprecation warning, use from_parent (#402) Signed-off-by: Dirk Thomas Signed-off-by: Shane Loretz --- launch_testing/launch_testing/pytest/hooks.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/launch_testing/launch_testing/pytest/hooks.py b/launch_testing/launch_testing/pytest/hooks.py index 8c90f51f7..8fb523530 100644 --- a/launch_testing/launch_testing/pytest/hooks.py +++ b/launch_testing/launch_testing/pytest/hooks.py @@ -34,10 +34,24 @@ def __str__(self): class LaunchTestItem(pytest.Item): - def __init__(self, name, parent, test_runs, runner_cls=LaunchTestRunner): + def __init__(self, parent, *, name): super().__init__(name, parent) - self.test_runs = test_runs - self.runner_cls = runner_cls + self.test_runs = None + self.runner_cls = None + + @classmethod + def from_parent( + cls, parent, *, name, test_runs, runner_cls=LaunchTestRunner + ): + """Override from_parent for compatibility.""" + # pytest.Item.from_parent didn't exist before pytest 5.4 + if hasattr(super(), 'from_parent'): + instance = getattr(super(), 'from_parent')(parent, name=name) + else: + instance = cls(parent, name=name) + instance.test_runs = test_runs + instance.runner_cls = runner_cls + return instance def runtest(self): launch_args = sum(( @@ -94,7 +108,7 @@ def from_parent(cls, parent, *, fspath): return instance def makeitem(self, *args, **kwargs): - return LaunchTestItem(*args, **kwargs) + return LaunchTestItem.from_parent(*args, **kwargs) def collect(self): module = self.fspath.pyimport()