2828 OutputChecker )
2929
3030_pytest_version = Version (pytest .__version__ )
31- PYTEST_GT_5 = _pytest_version > Version ('5.9.9' )
32- PYTEST_GE_5_4 = _pytest_version >= Version ('5.4' )
33- PYTEST_GE_7_0 = _pytest_version >= Version ('7.0' )
3431PYTEST_GE_8_0 = _pytest_version >= Version ('8.0' )
3532PYTEST_GE_8_1_1 = _pytest_version >= Version ('8.1.1' )
36- PYTEST_GE_8_2 = any ([_pytest_version .is_devrelease ,
37- _pytest_version .is_prerelease ,
38- _pytest_version >= Version ('8.2' )])
3933
4034comment_characters = {
4135 '.txt' : '#' ,
@@ -256,30 +250,21 @@ class DocTestModulePlus(doctest_plugin.DoctestModule):
256250 def collect (self ):
257251 # When running directly from pytest we need to make sure that we
258252 # don't accidentally import setup.py!
259- if PYTEST_GE_7_0 :
260- fspath = self .path
261- filepath = self .path .name
262- else :
263- fspath = self .fspath
264- filepath = self .fspath .basename
253+ fspath = self .path
254+ filepath = self .path .name
265255
266256 if filepath in ("setup.py" , "__main__.py" ):
267257 return
268258 try :
269- if PYTEST_GT_5 :
270- from _pytest .pathlib import import_path
271- mode = self .config .getoption ("importmode" )
259+ from _pytest .pathlib import import_path
260+ mode = self .config .getoption ("importmode" )
272261
273262 if PYTEST_GE_8_1_1 :
274263 consider_namespace_packages = self .config .getini ("consider_namespace_packages" )
275264 module = import_path (fspath , mode = mode , root = self .config .rootpath ,
276265 consider_namespace_packages = consider_namespace_packages )
277- elif PYTEST_GE_7_0 :
278- module = import_path (fspath , mode = mode , root = self .config .rootpath )
279- elif PYTEST_GT_5 :
280- module = import_path (fspath , mode = mode )
281266 else :
282- module = fspath . pyimport ( )
267+ module = import_path ( fspath , mode = mode , root = self . config . rootpath )
283268 except ImportError :
284269 if self .config .getvalue ("doctest_ignore_import_errors" ):
285270 pytest .skip ("unable to import module %r" % fspath )
@@ -345,12 +330,8 @@ class DocTestTextfilePlus(pytest.Module):
345330 obj = None
346331
347332 def collect (self ):
348- if PYTEST_GE_7_0 :
349- fspath = self .path
350- filepath = self .path .name
351- else :
352- fspath = self .fspath
353- filepath = self .fspath .basename
333+ fspath = self .path
334+ filepath = self .path .name
354335
355336 encoding = self .config .getini ("doctest_encoding" )
356337 text = fspath .read_text (encoding )
@@ -689,14 +670,10 @@ def pytest_ignore_collect(self, path, config):
689670 Skip paths that match any of the doctest_norecursedirs patterns or
690671 if doctest_only is True then skip all regular test files (eg test_*.py).
691672 """
692- if PYTEST_GE_7_0 :
693- dirpath = Path (path ).parent
694- collect_ignore = config ._getconftest_pathlist ("collect_ignore" ,
695- path = dirpath ,
696- rootpath = config .rootpath )
697- else :
698- dirpath = path .dirpath ()
699- collect_ignore = config ._getconftest_pathlist ("collect_ignore" , path = dirpath )
673+ dirpath = Path (path ).parent
674+ collect_ignore = config ._getconftest_pathlist ("collect_ignore" ,
675+ path = dirpath ,
676+ rootpath = config .rootpath )
700677
701678 # The collect_ignore conftest.py variable should cause all test
702679 # runners to ignore this file and all subfiles and subdirectories
@@ -779,12 +756,7 @@ def pytest_collect_file(self, path, parent):
779756 return None
780757
781758 # Don't override the built-in doctest plugin
782- if PYTEST_GE_7_0 :
783- return self ._doctest_module_item_cls .from_parent (parent , path = Path (path ))
784- elif PYTEST_GE_5_4 :
785- return self ._doctest_module_item_cls .from_parent (parent , fspath = path )
786- else :
787- return self ._doctest_module_item_cls (path , parent )
759+ return self ._doctest_module_item_cls .from_parent (parent , path = Path (path ))
788760
789761 elif any ([path .check (fnmatch = pat ) for pat in self ._file_globs ]):
790762 # Ignore generated .rst files
@@ -811,12 +783,7 @@ def pytest_collect_file(self, path, parent):
811783
812784 # TODO: Get better names on these items when they are
813785 # displayed in py.test output
814- if PYTEST_GE_7_0 :
815- return self ._doctest_textfile_item_cls .from_parent (parent , path = Path (path ))
816- elif PYTEST_GE_5_4 :
817- return self ._doctest_textfile_item_cls .from_parent (parent , fspath = path )
818- else :
819- return self ._doctest_textfile_item_cls (path , parent )
786+ return self ._doctest_textfile_item_cls .from_parent (parent , path = Path (path ))
820787
821788
822789class DocTestFinderPlus (doctest .DocTestFinder ):
@@ -930,7 +897,7 @@ def _prepend_importorskip(self, test, *, module):
930897 """Prepends `pytest.importorskip` before the doctest."""
931898 source = (
932899 "import pytest; "
933- # Hide output of this statement in `___`, otherwise doctests fail
900+ # Hide output of this statement in `___`, otherwise doctests fail
934901 f"___ = pytest.importorskip({ module !r} ); "
935902 # Don't impact what's available in the namespace
936903 "del pytest; del ___"
0 commit comments