@@ -115,6 +115,12 @@ def pytest_collection_modifyitems(items, config):
115
115
]
116
116
117
117
for item in items :
118
+ if config .getoption ("--doctest-modules" ) or config .getoption (
119
+ "--doctest-cython" , default = False
120
+ ):
121
+ # autouse=True for the add_doctest_imports can lead to expensive teardowns
122
+ # since doctest_namespace is a session fixture
123
+ item .add_marker (pytest .mark .usefixtures ("add_doctest_imports" ))
118
124
# mark all tests in the pandas/tests/frame directory with "arraymanager"
119
125
if "/frame/" in item .nodeid :
120
126
item .add_marker (pytest .mark .arraymanager )
@@ -187,6 +193,15 @@ def pytest_collection_modifyitems(items, config):
187
193
)
188
194
189
195
196
+ @pytest .fixture
197
+ def add_doctest_imports (doctest_namespace ):
198
+ """
199
+ Make `np` and `pd` names available for doctests.
200
+ """
201
+ doctest_namespace ["np" ] = np
202
+ doctest_namespace ["pd" ] = pd
203
+
204
+
190
205
# ----------------------------------------------------------------
191
206
# Autouse fixtures
192
207
# ----------------------------------------------------------------
@@ -198,15 +213,6 @@ def configure_tests():
198
213
pd .set_option ("chained_assignment" , "raise" )
199
214
200
215
201
- @pytest .fixture (autouse = True )
202
- def add_imports (doctest_namespace ):
203
- """
204
- Make `np` and `pd` names available for doctests.
205
- """
206
- doctest_namespace ["np" ] = np
207
- doctest_namespace ["pd" ] = pd
208
-
209
-
210
216
# ----------------------------------------------------------------
211
217
# Common arguments
212
218
# ----------------------------------------------------------------
0 commit comments