Skip to content

Commit a73e4f5

Browse files
committed
MAINT: plugin: run tests in a tempdir, stop blank filtering DeprecationWarnings
1 parent 33e85a4 commit a73e4f5

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

scpdt/plugin.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
from scpdt.impl import DTChecker, DTParser, DebugDTRunner
1515
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
1717
from scpdt.frontend import find_doctests
1818

1919

20+
# XXX: unused global?
2021
copied_files = []
2122

2223

@@ -107,6 +108,7 @@ def pytest_collection_modifyitems(config, items):
107108
items[:] = unique_items
108109

109110

111+
# XXX: unused?
110112
def copy_local_files(local_resources, destination_dir):
111113
"""
112114
Copy necessary local files for doctests to the current working directory.
@@ -165,8 +167,8 @@ def collect(self):
165167
raise
166168

167169
# 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+
# if self.config.dt_config.local_resources:
171+
# copy_local_files(self.config.dt_config.local_resources, os.getcwd())
170172

171173
optionflags = dt_config.optionflags
172174

@@ -254,10 +256,15 @@ def run(self, test, compileflags=None, out=None, clear_globs=False):
254256
*unless* the `mpl()` context mgr has a chance to filter them out
255257
*before* they become errors in `config.user_context_mgr()`.
256258
"""
259+
dt_config = config.dt_config
260+
261+
257262
with np_errstate():
258-
with config.dt_config.user_context_mgr(test):
263+
with dt_config.user_context_mgr(test):
259264
with matplotlib_make_nongui():
260-
super().run(test, compileflags=compileflags, out=out, clear_globs=clear_globs)
265+
# XXX: local_resourses needed? they seem to be, w/o pytest
266+
with temp_cwd(test, dt_config.local_resources):
267+
super().run(test, compileflags=compileflags, out=out, clear_globs=clear_globs)
261268

262269
"""
263270
Almost verbatim copy of `_pytest.doctest.PytestDoctestRunner` except we utilize

scpdt/tests/test_pytest_configuration.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
pytest_plugins = ['pytester']
1010

11-
11+
'''
1212
@pytest.fixture(autouse=True)
1313
def copy_files():
1414
"""
@@ -36,13 +36,10 @@ def copy_files():
3636
os.remove(filepath)
3737
except FileNotFoundError:
3838
pass
39-
40-
41-
"""
42-
Test that pytest uses the DTChecker for doctests
43-
"""
39+
'''
4440

4541
def test_module_cases(pytester):
42+
"""Test that pytest uses the DTChecker for doctests."""
4643
path_str = module_cases.__file__
4744
python_file = PosixPath(path_str)
4845
result = pytester.inline_run(python_file, "--doctest-modules")
@@ -58,21 +55,35 @@ def test_failure_cases(pytester):
5855
assert result.ret == pytest.ExitCode.TESTS_FAILED
5956

6057

61-
"""
62-
Test that pytest uses the DTParser for doctests
63-
"""
6458
def test_stopword_cases(pytester):
59+
"""Test that pytest uses the DTParser for doctests."""
6560
path_str = stopwords_cases.__file__
6661
python_file = PosixPath(path_str)
6762
result = pytester.inline_run(python_file, "--doctest-modules")
6863
assert result.ret == pytest.ExitCode.OK
6964

7065

71-
"""
72-
Test that local files are found for use in doctests
73-
"""
66+
#@pytest.mark.xfail
7467
def test_local_file_cases(pytester):
68+
"""Test that local files are found for use in doctests.
69+
70+
XXX: this one fails because nobody told pytest how to find those local files.
71+
cf test_testmod.py::TestLocalFiles
72+
"""
7573
path_str = local_file_cases.__file__
7674
python_file = PosixPath(path_str)
75+
76+
# pytester.makeconftest(
77+
# """
78+
# import pytest
79+
# from scpdt.conftest import dt_config
80+
#
81+
# dt_config.local_resources = {'scpdt.tests.local_file_cases.local_files':
82+
# ['local_file.txt']}
83+
# """
84+
# )
85+
86+
# breakpoint()
87+
7788
result = pytester.inline_run(python_file, "--doctest-modules")
7889
assert result.ret == pytest.ExitCode.OK

scpdt/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def temp_cwd(test, local_resources=None):
5858
# local files requested; copy the files
5959
path, _ = os.path.split(test.filename)
6060
for fname in local_resources[test.name]:
61-
shutil.copy(os.path.join(path, fname), tmpdir)
61+
shutil.copy(os.path.join(path, fname), tmpdir)
6262
try:
6363
os.chdir(tmpdir)
6464
yield tmpdir

0 commit comments

Comments
 (0)