From 06e3f05582961dae8abee0d6729dbf5e68063d82 Mon Sep 17 00:00:00 2001 From: Tony Najjar Date: Tue, 12 Mar 2024 17:49:23 +0000 Subject: [PATCH 1/2] Add consider_namespace_packages=False Signed-off-by: Tony Najjar --- launch_testing/launch_testing/pytest/hooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launch_testing/launch_testing/pytest/hooks.py b/launch_testing/launch_testing/pytest/hooks.py index de0035f76..ddff299ba 100644 --- a/launch_testing/launch_testing/pytest/hooks.py +++ b/launch_testing/launch_testing/pytest/hooks.py @@ -160,7 +160,7 @@ def collect(self): if _pytest_version_ge(7): # self.path exists since 7 from _pytest.pathlib import import_path - module = import_path(self.path, root=None) + module = import_path(self.path, root=None, consider_namespace_packages=False) else: module = self.fspath.pyimport() yield self.makeitem( @@ -175,7 +175,7 @@ def find_launch_test_entrypoint(path): try: if _pytest_version_ge(7): from _pytest.pathlib import import_path - module = import_path(path, root=None) + module = import_path(path, root=None, consider_namespace_packages=False) else: # Assume we got legacy path in earlier versions of pytest module = path.pyimport() From 106e47d92e53f00cac0d8a5f5494dd227e62a0fb Mon Sep 17 00:00:00 2001 From: Tony Najjar Date: Tue, 12 Mar 2024 18:39:27 +0000 Subject: [PATCH 2/2] depend on pytest version Signed-off-by: Tony Najjar --- launch_testing/launch_testing/pytest/hooks.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/launch_testing/launch_testing/pytest/hooks.py b/launch_testing/launch_testing/pytest/hooks.py index ddff299ba..174c4c476 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()