Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with pytest-dev #168

Merged
merged 1 commit into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems 7.0 will be the next version and there will not be a 6.3 release, but we can cleanup this later.


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