@@ -182,24 +182,37 @@ class DTModule(DoctestModule):
182
182
in the specified module or file.
183
183
"""
184
184
def collect (self ):
185
- # Part of this code is copy-pasted from the `_pytest.doctest` module(pytest 7.4.0):
186
- # https://github.com/pytest-dev/pytest/blob/448563caaac559b8a3195edc58e8806aca8d2c71/src/_pytest/doctest.py#L497
187
- if self .path .name == "setup.py" :
188
- return
189
- if self .path .name == "conftest.py" :
190
- module = self .config .pluginmanager ._importconftest (
191
- self .path ,
192
- self .config .getoption ("importmode" ),
193
- rootpath = self .config .rootpath
194
- )
195
- else :
196
- try :
197
- module = import_path (
185
+ if pytest .__version__ < '8' :
186
+ # Part of this code is copy-pasted from the `_pytest.doctest` module(pytest 7.4.0):
187
+ # https://github.com/pytest-dev/pytest/blob/448563caaac559b8a3195edc58e8806aca8d2c71/src/_pytest/doctest.py#L497
188
+ if self .path .name == "setup.py" :
189
+ return
190
+ if self .path .name == "conftest.py" :
191
+ module = self .config .pluginmanager ._importconftest (
198
192
self .path ,
199
- root = self .config .rootpath ,
200
- mode = self .config .getoption ( "importmode" ),
193
+ self .config .getoption ( "importmode" ) ,
194
+ rootpath = self .config .rootpath
201
195
)
202
- except ImportError :
196
+ else :
197
+ try :
198
+ module = import_path (
199
+ self .path ,
200
+ root = self .config .rootpath ,
201
+ mode = self .config .getoption ("importmode" ),
202
+ )
203
+ except ImportError :
204
+ if self .config .getvalue ("doctest_ignore_import_errors" ):
205
+ outcomes .skip ("unable to import module %r" % self .path )
206
+ else :
207
+ raise
208
+
209
+ # XXX: `assert module == self.obj` seems to work (so is it all automatic?)
210
+ # but what are failure modes
211
+ else :
212
+ # https://github.com/pytest-dev/pytest/blob/8.1.0/src/_pytest/doctest.py#L561
213
+ try :
214
+ module = self .obj
215
+ except _pytest .nodes .Collector .CollectError :
203
216
if self .config .getvalue ("doctest_ignore_import_errors" ):
204
217
outcomes .skip ("unable to import module %r" % self .path )
205
218
else :
0 commit comments