From 65ed077e1defe79adc7651e5162a170ebbf0528b Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Mon, 15 Nov 2021 18:17:15 +0100 Subject: [PATCH] Compatibility with pytest-dev --- pytest_doctestplus/plugin.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pytest_doctestplus/plugin.py b/pytest_doctestplus/plugin.py index 86e3b13..8b7127d 100644 --- a/pytest_doctestplus/plugin.py +++ b/pytest_doctestplus/plugin.py @@ -22,8 +22,9 @@ _pytest_version = Version(pytest.__version__) PYTEST_GT_5 = _pytest_version > Version('5.9.9') +PYTEST_GE_5_4 = _pytest_version >= Version('5.4') PYTEST_GE_6_3 = _pytest_version.is_devrelease or _pytest_version >= Version('6.3') -PYTEST_GT_6_3 = _pytest_version.is_devrelease or _pytest_version > Version('6.3') +PYTEST_GE_7_0 = _pytest_version.is_devrelease or _pytest_version >= Version('7.0') comment_characters = { '.txt': '#', @@ -201,7 +202,7 @@ def collect(self): if filepath == "setup.py": return elif filepath == "conftest.py": - if PYTEST_GT_6_3: + if PYTEST_GE_7_0: module = self.config.pluginmanager._importconftest( self.path, self.config.getoption("importmode"), rootpath=self.config.rootpath) @@ -567,10 +568,11 @@ def pytest_collect_file(self, path, parent): return None # Don't override the built-in doctest plugin - try: + if PYTEST_GE_7_0: + return self._doctest_module_item_cls.from_parent(parent, path=Path(path)) + elif PYTEST_GE_5_4: return self._doctest_module_item_cls.from_parent(parent, fspath=path) - except AttributeError: - # pytest < 5.4 + else: return self._doctest_module_item_cls(path, parent) elif any([path.check(fnmatch=pat) for pat in self._file_globs]): @@ -598,10 +600,11 @@ def pytest_collect_file(self, path, parent): # TODO: Get better names on these items when they are # displayed in py.test output - try: + if PYTEST_GE_7_0: + return self._doctest_textfile_item_cls.from_parent(parent, path=Path(path)) + elif PYTEST_GE_5_4: return self._doctest_textfile_item_cls.from_parent(parent, fspath=path) - except AttributeError: - # pytest < 5.4 + else: return self._doctest_textfile_item_cls(path, parent)