Skip to content

Commit

Permalink
depend on pytest version
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Najjar <[email protected]>
  • Loading branch information
tonynajjar committed Mar 12, 2024
1 parent 06e3f05 commit 106e47d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions launch_testing/launch_testing/pytest/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
Expand Down

0 comments on commit 106e47d

Please sign in to comment.