99
1010from typing import Any , Iterable , Union
1111
12- from _pytest .nodes import Collector
13- from _pytest .doctest import skip , DoctestModule , DoctestItem
12+ from _pytest .doctest import DoctestModule , DoctestItem
1413from _pytest .pathlib import resolve_package_path , ImportMode
1514
1615
@@ -33,15 +32,11 @@ def pytest_addoption(parser: pytest.Parser):
3332 )
3433
3534
36- def pytest_collect_file (file_path : pathlib .Path , path , parent : pytest .Collector ) -> pytest .Module :
35+ def pytest_collect_file (file_path : pathlib .Path , parent : pytest .Collector ) -> pytest .Module :
3736 config = parent .config
3837 if file_path .suffix not in CYTHON_SUFFIXES or not config .getoption ('--doctest-cython' ):
3938 return
4039
41- bin_path = file_path .with_suffix (EXT_SUFFIX )
42- if not bin_path .exists ():
43- return
44-
4540 # only run test if matching .so and .pyx files exist
4641 return _PatchedDoctestModule .from_parent (parent , path = file_path )
4742
@@ -62,15 +57,6 @@ def collect(self) -> Iterable[DoctestItem]:
6257 os .environ [IGNORE_IMPORTMISMATCH_KEY ] = IGNORE_IMPORTMISMATCH
6358
6459 module = self .obj # module already imported
65-
66- try :
67- _check_module_import (module , self .path , mode )
68- except Collector .CollectError :
69- if self .config .getvalue ("doctest_ignore_import_errors" ):
70- skip ("unable to import module %r" % self .path )
71- else :
72- raise
73-
7460 return _add_line_numbers (module , items )
7561
7662
@@ -94,30 +80,6 @@ def _get_module_name(path: pathlib.Path) -> str:
9480 return module_name
9581
9682
97- def _check_module_import (module : Any , path : pathlib .Path , mode : ImportMode ) -> None :
98- # double check that the only difference is the extension else raise an exception
99-
100- if mode is ImportMode .importlib or IGNORE_IMPORTMISMATCH == "1" :
101- return
102-
103- module_name = _get_module_name (path )
104- module_file = _without_suffixes (module .__file__ )
105- import_file = _without_suffixes (path )
106-
107- if module_file == import_file :
108- return
109-
110- raise Collector .CollectError (
111- "import file mismatch:\n "
112- "imported module %r has this __file__ attribute:\n "
113- " %s\n "
114- "which is not the same as the test file we want to collect:\n "
115- " %s\n "
116- "HINT: remove __pycache__ / .pyc files and/or use a "
117- "unique basename for your test file modules" % (module_name , module_file , import_file )
118- )
119-
120-
12183def _add_line_numbers (module : Any , items : Iterable [DoctestItem ]) -> Iterable [DoctestItem ]:
12284 # handle tests from Cython's internal __test__ dict generated by
12385 # the autotestdict directive; we exclude the tests from __test__,
0 commit comments