Skip to content

Commit

Permalink
Merge pull request #168 from saimn/fix-pytestdev
Browse files Browse the repository at this point in the history
Compatibility with pytest-dev
  • Loading branch information
pllim authored Nov 15, 2021
2 parents d421789 + 65ed077 commit f40161f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pytest_doctestplus/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '#',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]):
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit f40161f

Please sign in to comment.