Skip to content

Commit

Permalink
Support for pytest 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
freider committed Mar 4, 2024
1 parent 6578644 commit 2e61471
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions src/pytest_markdown_docs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from _pytest.pathlib import import_path
from pytest_markdown_docs import hooks

try:
# pytest 8

if pytest.version_tuple >= (8, 0, 0):
from _pytest.fixtures import TopRequest
except ImportError:
else:
# pytest 7 compatible
from _pytest.fixtures import FixtureRequest as TopRequest # type: ignore

Expand Down Expand Up @@ -204,7 +204,15 @@ def find_object_tests_recursive(

class MarkdownDocstringCodeModule(pytest.Module):
def collect(self):
module = import_path(self.path, root=self.config.rootpath)
if pytest.version_tuple >= (8, 1, 0):
# consider_namespace_packages is a required keyword argument in pytest 8.1.0
module = import_path(
self.path, root=self.config.rootpath, consider_namespace_packages=True
)
else:
# but unsupported before 8.1...
module = import_path(self.path, root=self.config.rootpath)

for i, (test_code, fixture_names, start_line) in enumerate(
find_object_tests_recursive(module.__name__, module.__name__, module)
):
Expand Down Expand Up @@ -236,11 +244,11 @@ def collect(self):


def pytest_collect_file(
path,
file_path,
parent,
):
if parent.config.option.markdowndocs:
pathlib_path = pathlib.Path(str(path)) # pytest 7/8 compat
pathlib_path = pathlib.Path(str(file_path)) # pytest 7/8 compat
if pathlib_path.suffix == ".py":
return MarkdownDocstringCodeModule.from_parent(parent, path=pathlib_path)
elif pathlib_path.suffix in (".md", ".mdx", ".svx"):
Expand Down

0 comments on commit 2e61471

Please sign in to comment.