Show More
@@ -38,7 +38,11 b' from _pytest._io import TerminalWriter' | |||||
38 | from _pytest.compat import safe_getattr |
|
38 | from _pytest.compat import safe_getattr | |
39 | from _pytest.config import Config |
|
39 | from _pytest.config import Config | |
40 | from _pytest.config.argparsing import Parser |
|
40 | from _pytest.config.argparsing import Parser | |
41 | from _pytest.fixtures import FixtureRequest |
|
41 | ||
|
42 | try: | |||
|
43 | from _pytest.fixtures import TopRequest as FixtureRequest | |||
|
44 | except ImportError: | |||
|
45 | from _pytest.fixtures import FixtureRequest | |||
42 | from _pytest.nodes import Collector |
|
46 | from _pytest.nodes import Collector | |
43 | from _pytest.outcomes import OutcomeException |
|
47 | from _pytest.outcomes import OutcomeException | |
44 | from _pytest.pathlib import fnmatch_ex, import_path |
|
48 | from _pytest.pathlib import fnmatch_ex, import_path | |
@@ -69,6 +73,8 b' RUNNER_CLASS = None' | |||||
69 | # Lazy definition of output checker class |
|
73 | # Lazy definition of output checker class | |
70 | CHECKER_CLASS: Optional[Type["IPDoctestOutputChecker"]] = None |
|
74 | CHECKER_CLASS: Optional[Type["IPDoctestOutputChecker"]] = None | |
71 |
|
75 | |||
|
76 | pytest_version = tuple([int(part) for part in pytest.__version__.split(".")]) | |||
|
77 | ||||
72 |
|
78 | |||
73 | def pytest_addoption(parser: Parser) -> None: |
|
79 | def pytest_addoption(parser: Parser) -> None: | |
74 | parser.addini( |
|
80 | parser.addini( | |
@@ -143,7 +149,7 b' def pytest_collect_file(' | |||||
143 | return None |
|
149 | return None | |
144 |
|
150 | |||
145 |
|
151 | |||
146 |
if |
|
152 | if pytest_version[0] < 7: | |
147 | _collect_file = pytest_collect_file |
|
153 | _collect_file = pytest_collect_file | |
148 |
|
154 | |||
149 | def pytest_collect_file( |
|
155 | def pytest_collect_file( | |
@@ -448,7 +454,7 b' class IPDoctestItem(pytest.Item):' | |||||
448 | assert self.dtest is not None |
|
454 | assert self.dtest is not None | |
449 | return self.path, self.dtest.lineno, "[ipdoctest] %s" % self.name |
|
455 | return self.path, self.dtest.lineno, "[ipdoctest] %s" % self.name | |
450 |
|
456 | |||
451 |
if |
|
457 | if pytest_version[0] < 7: | |
452 |
|
458 | |||
453 | @property |
|
459 | @property | |
454 | def path(self) -> Path: |
|
460 | def path(self) -> Path: | |
@@ -521,7 +527,7 b' class IPDoctestTextfile(pytest.Module):' | |||||
521 | self, name=test.name, runner=runner, dtest=test |
|
527 | self, name=test.name, runner=runner, dtest=test | |
522 | ) |
|
528 | ) | |
523 |
|
529 | |||
524 |
if |
|
530 | if pytest_version[0] < 7: | |
525 |
|
531 | |||
526 | @property |
|
532 | @property | |
527 | def path(self) -> Path: |
|
533 | def path(self) -> Path: | |
@@ -636,20 +642,26 b' class IPDoctestModule(pytest.Module):' | |||||
636 | ) |
|
642 | ) | |
637 |
|
643 | |||
638 | if self.path.name == "conftest.py": |
|
644 | if self.path.name == "conftest.py": | |
639 |
if |
|
645 | if pytest_version[0] < 7: | |
640 | module = self.config.pluginmanager._importconftest( |
|
646 | module = self.config.pluginmanager._importconftest( | |
641 | self.path, |
|
647 | self.path, | |
642 | self.config.getoption("importmode"), |
|
648 | self.config.getoption("importmode"), | |
643 | ) |
|
649 | ) | |
644 | else: |
|
650 | else: | |
|
651 | kwargs = {"rootpath": self.config.rootpath} | |||
|
652 | if pytest_version >= (8, 1): | |||
|
653 | kwargs["consider_namespace_packages"] = False | |||
645 | module = self.config.pluginmanager._importconftest( |
|
654 | module = self.config.pluginmanager._importconftest( | |
646 | self.path, |
|
655 | self.path, | |
647 | self.config.getoption("importmode"), |
|
656 | self.config.getoption("importmode"), | |
648 | rootpath=self.config.rootpath, |
|
657 | **kwargs, | |
649 | ) |
|
658 | ) | |
650 | else: |
|
659 | else: | |
651 | try: |
|
660 | try: | |
652 |
|
|
661 | kwargs = {"root": self.config.rootpath} | |
|
662 | if pytest_version >= (8, 1): | |||
|
663 | kwargs["consider_namespace_packages"] = False | |||
|
664 | module = import_path(self.path, **kwargs) | |||
653 | except ImportError: |
|
665 | except ImportError: | |
654 | if self.config.getvalue("ipdoctest_ignore_import_errors"): |
|
666 | if self.config.getvalue("ipdoctest_ignore_import_errors"): | |
655 | pytest.skip("unable to import module %r" % self.path) |
|
667 | pytest.skip("unable to import module %r" % self.path) | |
@@ -671,7 +683,7 b' class IPDoctestModule(pytest.Module):' | |||||
671 | self, name=test.name, runner=runner, dtest=test |
|
683 | self, name=test.name, runner=runner, dtest=test | |
672 | ) |
|
684 | ) | |
673 |
|
685 | |||
674 |
if |
|
686 | if pytest_version[0] < 7: | |
675 |
|
687 | |||
676 | @property |
|
688 | @property | |
677 | def path(self) -> Path: |
|
689 | def path(self) -> Path: | |
@@ -701,11 +713,15 b' def _setup_fixtures(doctest_item: IPDoctestItem) -> FixtureRequest:' | |||||
701 |
|
713 | |||
702 | doctest_item.funcargs = {} # type: ignore[attr-defined] |
|
714 | doctest_item.funcargs = {} # type: ignore[attr-defined] | |
703 | fm = doctest_item.session._fixturemanager |
|
715 | fm = doctest_item.session._fixturemanager | |
|
716 | kwargs = {"node": doctest_item, "func": func, "cls": None} | |||
|
717 | if pytest_version <= (8, 0): | |||
|
718 | kwargs["funcargs"] = False | |||
704 | doctest_item._fixtureinfo = fm.getfixtureinfo( # type: ignore[attr-defined] |
|
719 | doctest_item._fixtureinfo = fm.getfixtureinfo( # type: ignore[attr-defined] | |
705 | node=doctest_item, func=func, cls=None, funcargs=False |
|
720 | **kwargs | |
706 | ) |
|
721 | ) | |
707 | fixture_request = FixtureRequest(doctest_item, _ispytest=True) |
|
722 | fixture_request = FixtureRequest(doctest_item, _ispytest=True) | |
708 | fixture_request._fillfixtures() |
|
723 | if pytest_version <= (8, 0): | |
|
724 | fixture_request._fillfixtures() | |||
709 | return fixture_request |
|
725 | return fixture_request | |
710 |
|
726 | |||
711 |
|
727 |
General Comments 0
You need to be logged in to leave comments.
Login now