diff --git a/launch_testing/launch_testing/pytest/hooks.py b/launch_testing/launch_testing/pytest/hooks.py index ddff299b..174c4c47 100644 --- a/launch_testing/launch_testing/pytest/hooks.py +++ b/launch_testing/launch_testing/pytest/hooks.py @@ -157,10 +157,12 @@ def makeitem(self, *args, **kwargs): return LaunchTestItem.from_parent(*args, **kwargs) def collect(self): - if _pytest_version_ge(7): - # self.path exists since 7 + if _pytest_version_ge(8, 1, 0): from _pytest.pathlib import import_path module = import_path(self.path, root=None, consider_namespace_packages=False) + elif _pytest_version_ge(7, 0, 0): + from _pytest.pathlib import import_path + module = import_path(self.path, root=None) else: module = self.fspath.pyimport() yield self.makeitem( @@ -173,9 +175,12 @@ def collect(self): def find_launch_test_entrypoint(path): try: - if _pytest_version_ge(7): + if _pytest_version_ge(8, 1, 0): from _pytest.pathlib import import_path module = import_path(path, root=None, consider_namespace_packages=False) + elif _pytest_version_ge(7, 0, 0): + from _pytest.pathlib import import_path + module = import_path(path, root=None) else: # Assume we got legacy path in earlier versions of pytest module = path.pyimport()