13
13
14
14
from scpdt .impl import DTChecker , DTParser , DebugDTRunner
15
15
from scpdt .conftest import dt_config
16
- from scpdt .util import np_errstate , matplotlib_make_nongui
16
+ from scpdt .util import np_errstate , matplotlib_make_nongui , temp_cwd
17
17
from scpdt .frontend import find_doctests
18
18
19
19
20
- copied_files = []
21
-
22
-
23
20
def pytest_configure (config ):
24
21
"""
25
22
Perform initial configuration for the pytest plugin.
@@ -33,20 +30,6 @@ def pytest_configure(config):
33
30
pydoctest .DoctestTextfile = DTTextfile
34
31
35
32
36
- def pytest_unconfigure (config ):
37
- """
38
- Called before exiting the test process.
39
- """
40
-
41
- # Delete all locally copied files in the current working directory
42
- if copied_files :
43
- try :
44
- for filepath in copied_files :
45
- os .remove (filepath )
46
- except FileNotFoundError :
47
- pass
48
-
49
-
50
33
def pytest_ignore_collect (collection_path , config ):
51
34
"""
52
35
Determine whether to ignore the specified collection path.
@@ -105,31 +88,6 @@ def pytest_collection_modifyitems(config, items):
105
88
106
89
# Replace the original list of test items with the unique ones
107
90
items [:] = unique_items
108
-
109
-
110
- def copy_local_files (local_resources , destination_dir ):
111
- """
112
- Copy necessary local files for doctests to the current working directory.
113
-
114
- This function copies files specified in the `local_resources` attribute of a DTConfig instance
115
- to the specified `destination_dir`.
116
-
117
- Args:
118
- local_resources (dict): A dictionary of resources to be copied.
119
- destination_dir (str): The destination directory where files will be copied.
120
-
121
- Returns:
122
- list: A list of paths to the copied files.
123
- """
124
- for value in local_resources .values ():
125
- for filepath in value :
126
- basename = os .path .basename (filepath )
127
- dest_path = os .path .join (destination_dir , basename )
128
-
129
- if not os .path .exists (dest_path ):
130
- shutil .copy (filepath , destination_dir )
131
- copied_files .append (dest_path )
132
- return copied_files
133
91
134
92
135
93
class DTModule (DoctestModule ):
@@ -164,10 +122,6 @@ def collect(self):
164
122
else :
165
123
raise
166
124
167
- # Copy local files specified by the `local_resources` attribute to the current working directory
168
- if self .config .dt_config .local_resources :
169
- copy_local_files (self .config .dt_config .local_resources , os .getcwd ())
170
-
171
125
optionflags = dt_config .optionflags
172
126
173
127
# Plug in the custom runner: `PytestDTRunner`
@@ -208,10 +162,6 @@ def collect(self):
208
162
209
163
optionflags = pydoctest .get_optionflags (self )
210
164
211
- # Copy local files specified by the `local_resources` attribute to the current working directory
212
- if self .config .dt_config .local_resources :
213
- copy_local_files (self .config .dt_config .local_resources , os .getcwd ())
214
-
215
165
# Plug in the custom runner: `PytestDTRunner`
216
166
runner = _get_runner (self .config ,
217
167
verbose = False ,
@@ -254,10 +204,15 @@ def run(self, test, compileflags=None, out=None, clear_globs=False):
254
204
*unless* the `mpl()` context mgr has a chance to filter them out
255
205
*before* they become errors in `config.user_context_mgr()`.
256
206
"""
207
+ dt_config = config .dt_config
208
+
209
+
257
210
with np_errstate ():
258
- with config . dt_config .user_context_mgr (test ):
211
+ with dt_config .user_context_mgr (test ):
259
212
with matplotlib_make_nongui ():
260
- super ().run (test , compileflags = compileflags , out = out , clear_globs = clear_globs )
213
+ # XXX: local_resourses needed? they seem to be, w/o pytest
214
+ with temp_cwd (test , dt_config .local_resources ):
215
+ super ().run (test , compileflags = compileflags , out = out , clear_globs = clear_globs )
261
216
262
217
"""
263
218
Almost verbatim copy of `_pytest.doctest.PytestDoctestRunner` except we utilize
0 commit comments