Show More
@@ -142,6 +142,23 b' def pytest_collect_file(' | |||||
142 | return None |
|
142 | return None | |
143 |
|
143 | |||
144 |
|
144 | |||
|
145 | if int(pytest.__version__.split(".")[0]) < 7: | |||
|
146 | _collect_file = pytest_collect_file | |||
|
147 | ||||
|
148 | def pytest_collect_file( | |||
|
149 | path, | |||
|
150 | parent: Collector, | |||
|
151 | ) -> Optional[Union["IPDoctestModule", "IPDoctestTextfile"]]: | |||
|
152 | return _collect_file(Path(path), parent) | |||
|
153 | ||||
|
154 | _import_path = import_path | |||
|
155 | ||||
|
156 | def import_path(path, root): | |||
|
157 | import py.path | |||
|
158 | ||||
|
159 | return _import_path(py.path.local(path)) | |||
|
160 | ||||
|
161 | ||||
145 | def _is_setup_py(path: Path) -> bool: |
|
162 | def _is_setup_py(path: Path) -> bool: | |
146 | if path.name != "setup.py": |
|
163 | if path.name != "setup.py": | |
147 | return False |
|
164 | return False | |
@@ -427,6 +444,12 b' class IPDoctestItem(pytest.Item):' | |||||
427 | assert self.dtest is not None |
|
444 | assert self.dtest is not None | |
428 | return self.path, self.dtest.lineno, "[ipdoctest] %s" % self.name |
|
445 | return self.path, self.dtest.lineno, "[ipdoctest] %s" % self.name | |
429 |
|
446 | |||
|
447 | if int(pytest.__version__.split(".")[0]) < 7: | |||
|
448 | ||||
|
449 | @property | |||
|
450 | def path(self) -> Path: | |||
|
451 | return Path(self.fspath) | |||
|
452 | ||||
430 |
|
453 | |||
431 | def _get_flag_lookup() -> Dict[str, int]: |
|
454 | def _get_flag_lookup() -> Dict[str, int]: | |
432 | import doctest |
|
455 | import doctest | |
@@ -494,6 +517,27 b' class IPDoctestTextfile(pytest.Module):' | |||||
494 | self, name=test.name, runner=runner, dtest=test |
|
517 | self, name=test.name, runner=runner, dtest=test | |
495 | ) |
|
518 | ) | |
496 |
|
519 | |||
|
520 | if int(pytest.__version__.split(".")[0]) < 7: | |||
|
521 | ||||
|
522 | @property | |||
|
523 | def path(self) -> Path: | |||
|
524 | return Path(self.fspath) | |||
|
525 | ||||
|
526 | @classmethod | |||
|
527 | def from_parent( | |||
|
528 | cls, | |||
|
529 | parent, | |||
|
530 | *, | |||
|
531 | fspath=None, | |||
|
532 | path: Optional[Path] = None, | |||
|
533 | **kw, | |||
|
534 | ): | |||
|
535 | if path is not None: | |||
|
536 | import py.path | |||
|
537 | ||||
|
538 | fspath = py.path.local(path) | |||
|
539 | return super().from_parent(parent=parent, fspath=fspath, **kw) | |||
|
540 | ||||
497 |
|
541 | |||
498 | def _check_all_skipped(test: "doctest.DocTest") -> None: |
|
542 | def _check_all_skipped(test: "doctest.DocTest") -> None: | |
499 | """Raise pytest.skip() if all examples in the given DocTest have the SKIP |
|
543 | """Raise pytest.skip() if all examples in the given DocTest have the SKIP | |
@@ -589,11 +633,17 b' class IPDoctestModule(pytest.Module):' | |||||
589 | ) |
|
633 | ) | |
590 |
|
634 | |||
591 | if self.path.name == "conftest.py": |
|
635 | if self.path.name == "conftest.py": | |
592 | module = self.config.pluginmanager._importconftest( |
|
636 | if int(pytest.__version__.split(".")[0]) < 7: | |
593 | self.path, |
|
637 | module = self.config.pluginmanager._importconftest( | |
594 | self.config.getoption("importmode"), |
|
638 | self.path, | |
595 |
|
|
639 | self.config.getoption("importmode"), | |
596 | ) |
|
640 | ) | |
|
641 | else: | |||
|
642 | module = self.config.pluginmanager._importconftest( | |||
|
643 | self.path, | |||
|
644 | self.config.getoption("importmode"), | |||
|
645 | rootpath=self.config.rootpath, | |||
|
646 | ) | |||
597 | else: |
|
647 | else: | |
598 | try: |
|
648 | try: | |
599 | module = import_path(self.path, root=self.config.rootpath) |
|
649 | module = import_path(self.path, root=self.config.rootpath) | |
@@ -618,6 +668,27 b' class IPDoctestModule(pytest.Module):' | |||||
618 | self, name=test.name, runner=runner, dtest=test |
|
668 | self, name=test.name, runner=runner, dtest=test | |
619 | ) |
|
669 | ) | |
620 |
|
670 | |||
|
671 | if int(pytest.__version__.split(".")[0]) < 7: | |||
|
672 | ||||
|
673 | @property | |||
|
674 | def path(self) -> Path: | |||
|
675 | return Path(self.fspath) | |||
|
676 | ||||
|
677 | @classmethod | |||
|
678 | def from_parent( | |||
|
679 | cls, | |||
|
680 | parent, | |||
|
681 | *, | |||
|
682 | fspath=None, | |||
|
683 | path: Optional[Path] = None, | |||
|
684 | **kw, | |||
|
685 | ): | |||
|
686 | if path is not None: | |||
|
687 | import py.path | |||
|
688 | ||||
|
689 | fspath = py.path.local(path) | |||
|
690 | return super().from_parent(parent=parent, fspath=fspath, **kw) | |||
|
691 | ||||
621 |
|
692 | |||
622 | def _setup_fixtures(doctest_item: IPDoctestItem) -> FixtureRequest: |
|
693 | def _setup_fixtures(doctest_item: IPDoctestItem) -> FixtureRequest: | |
623 | """Used by IPDoctestTextfile and IPDoctestItem to setup fixture information.""" |
|
694 | """Used by IPDoctestTextfile and IPDoctestItem to setup fixture information.""" | |
@@ -711,7 +782,7 b' def _init_checker_class() -> Type["IPDoctestOutputChecker"]:' | |||||
711 | precision = 0 if fraction is None else len(fraction) |
|
782 | precision = 0 if fraction is None else len(fraction) | |
712 | if exponent is not None: |
|
783 | if exponent is not None: | |
713 | precision -= int(exponent) |
|
784 | precision -= int(exponent) | |
714 | if float(w.group()) == approx(float(g.group()), abs=10**-precision): |
|
785 | if float(w.group()) == approx(float(g.group()), abs=10 ** -precision): | |
715 | # They're close enough. Replace the text we actually |
|
786 | # They're close enough. Replace the text we actually | |
716 | # got with the text we want, so that it will match when we |
|
787 | # got with the text we want, so that it will match when we | |
717 | # check the string literally. |
|
788 | # check the string literally. |
General Comments 0
You need to be logged in to leave comments.
Login now