@@ -155,6 +155,22 @@ def pytest_collection_modifyitems(config, items):
155
155
items [:] = unique_items
156
156
157
157
158
+ def _is_deprecated (module ):
159
+ """Detect if a module is deprecated (i.e., raises or warns on getattr)."""
160
+ names = dir (module )
161
+ if not names :
162
+ return False
163
+
164
+ res = False
165
+ try :
166
+ getattr (module , names [0 ])
167
+ res = False
168
+ except DeprecationWarning :
169
+ res = True
170
+
171
+ return res
172
+
173
+
158
174
class DTModule (DoctestModule ):
159
175
"""
160
176
This class extends the DoctestModule class provided by pytest.
@@ -187,6 +203,10 @@ def collect(self):
187
203
else :
188
204
raise
189
205
206
+ if _is_deprecated (module ):
207
+ # bail out early
208
+ return
209
+
190
210
optionflags = dt_config .optionflags
191
211
192
212
# Plug in the custom runner: `PytestDTRunner`
@@ -202,15 +222,12 @@ def collect(self):
202
222
if strategy == 'None' :
203
223
strategy = None
204
224
205
- try :
206
- # NB: additional postprocessing in pytest_collection_modifyitems
207
- for test in find_doctests (module , strategy = strategy , name = module .__name__ , config = dt_config ):
208
- if test .examples : # skip empty doctests
209
- yield pydoctest .DoctestItem .from_parent (
210
- self , name = test .name , runner = runner , dtest = test
211
- )
212
- except :
213
- pass
225
+ # NB: additional postprocessing in pytest_collection_modifyitems
226
+ for test in find_doctests (module , strategy = strategy , name = module .__name__ , config = dt_config ):
227
+ if test .examples : # skip empty doctests
228
+ yield pydoctest .DoctestItem .from_parent (
229
+ self , name = test .name , runner = runner , dtest = test
230
+ )
214
231
215
232
216
233
class DTTextfile (DoctestTextfile ):
0 commit comments