Skip to content

Commit d148aa5

Browse files
authored
Merge pull request #110 from ev-br/pytest_warns
MAINT: avoid pytest future warnings
2 parents 0619a82 + 32b1d82 commit d148aa5

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

scpdt/tests/test_testmod.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,77 +17,73 @@
1717
failure_cases,
1818
failure_cases_2,
1919
local_file_cases)
20-
from ..frontend import testmod, find_doctests, run_docstring_examples
20+
from ..frontend import testmod as _testmod, find_doctests, run_docstring_examples
2121
from ..util import warnings_errors
2222
from ..impl import DTConfig
2323

2424
_VERBOSE = 2
2525

2626

2727
def test_module():
28-
res, _ = testmod(module, verbose=_VERBOSE)
29-
if res.failed != 0 or res.attempted == 0:
30-
raise RuntimeError("Test_module(DTFinder) failed)")
31-
return res
28+
res, _ = _testmod(module, verbose=_VERBOSE)
29+
assert res.failed == 0
30+
assert res.attempted != 0
3231

3332

3433
def test_module_vanilla_dtfinder():
3534
config = DTConfig()
3635
config.stopwords = []
37-
res, _ = testmod(module, verbose=_VERBOSE, config=config)
38-
if res.failed != 0 or res.attempted == 0:
39-
raise RuntimeError("Test_module(vanilla DocTestFinder) failed)")
40-
return res
36+
res, _ = _testmod(module, verbose=_VERBOSE, config=config)
37+
assert res.failed == 0
38+
assert res.attempted != 0
4139

4240

4341
def test_stopwords():
44-
res, _ = testmod(stopwords, verbose=_VERBOSE)
45-
if res.failed != 0 or res.attempted == 0:
46-
raise RuntimeError("Test_stopwords failed.")
47-
return res
42+
res, _ = _testmod(stopwords, verbose=_VERBOSE)
43+
assert res.failed == 0
44+
assert res.attempted != 0
4845

4946

5047
def test_public_obj_discovery():
51-
res, _ = testmod(module, verbose=_VERBOSE, strategy='api')
52-
if res.failed != 0 or res.attempted == 0:
53-
raise RuntimeError("Test_public_obj failed.")
54-
return res
48+
res, _ = _testmod(module, verbose=_VERBOSE, strategy='api')
49+
assert res.failed == 0
50+
assert res.attempted != 0
5551

5652

5753
def test_run_docstring_examples():
5854
f = finder_cases.Klass
5955
res1 = run_docstring_examples(f)
60-
res2 = testmod(finder_cases, strategy=[finder_cases.Klass])
56+
res2 = _testmod(finder_cases, strategy=[finder_cases.Klass])
6157
assert res1 == res2
6258

6359

6460
def test_global_state():
6561
# Make sure doctesting does not alter the global state, as much as reasonable
6662
objs = [module.manip_printoptions]
6763
opts = np.get_printoptions()
68-
testmod(module)
64+
_testmod(module)
6965
new_opts = np.get_printoptions()
7066
assert new_opts == opts
7167

7268

7369
def test_module_debugrunner():
7470
with pytest.raises((doctest.UnexpectedException, doctest.DocTestFailure)):
75-
res = testmod(failure_cases, raise_on_error=True)
71+
res = _testmod(failure_cases, raise_on_error=True)
7672

7773

7874
def test_verbosity_1():
7975
# smoke test that verbose=1 works
8076
stream = io.StringIO()
8177
with redirect_stderr(stream):
82-
testmod(failure_cases, verbose=1, report=False)
78+
_testmod(failure_cases, verbose=1, report=False)
8379

8480

8581
def test_user_context():
8682
# use a user context to turn warnings to errors : test that it raises
8783
config = DTConfig()
8884
config.user_context_mgr = warnings_errors
8985
with pytest.raises(doctest.UnexpectedException):
90-
testmod(failure_cases_2,
86+
_testmod(failure_cases_2,
9187
raise_on_error=True, strategy=[failure_cases_2.func_depr],
9288
config=config)
9389

@@ -99,23 +95,25 @@ def test_local_files(self):
9995
config = DTConfig()
10096
config.local_resources = {'scpdt.tests.local_file_cases.local_files':
10197
['local_file.txt']}
102-
res, _ = testmod(local_file_cases, config=config,
98+
res, _ = _testmod(local_file_cases, config=config,
10399
strategy=[local_file_cases.local_files],
104100
verbose=_VERBOSE)
105-
if res.failed != 0 or res.attempted == 0:
106-
raise RuntimeError("Test_module::test_local_files")
101+
102+
assert res.failed == 0
103+
assert res.attempted != 0
107104

108105
@pytest.mark.skipif(not HAVE_SCIPY, reason='need scipy')
109106
def test_sio_octave(self):
110107
# scipy/tutorial/io.rst : octave_a.mat file
111108
config = DTConfig()
112109
config.local_resources = {'scpdt.tests.local_file_cases.sio':
113110
['octave_a.mat']}
114-
res, _ = testmod(local_file_cases, config=config,
115-
strategy=[local_file_cases.sio],
116-
verbose=_VERBOSE)
117-
if res.failed != 0 or res.attempted == 0:
118-
raise RuntimeError("Test_module::sio")
111+
res, _ = _testmod(local_file_cases, config=config,
112+
strategy=[local_file_cases.sio],
113+
verbose=_VERBOSE)
114+
115+
assert res.failed == 0
116+
assert res.attempted != 0
119117

120118

121119
class TestNameErrorAfterException:
@@ -125,8 +123,8 @@ def test_name_error_after_exception(self):
125123
# This first came in in https://github.com/scipy/scipy/pull/13116
126124
stream = io.StringIO()
127125
with redirect_stderr(stream):
128-
testmod(failure_cases_2,
129-
strategy=[failure_cases_2.func_name_error])
126+
_testmod(failure_cases_2,
127+
strategy=[failure_cases_2.func_name_error])
130128

131129
stream.seek(0)
132130
output = stream.read()
@@ -139,8 +137,8 @@ def test_name_error_after_exception_off(self):
139137
config = DTConfig(nameerror_after_exception=True)
140138
stream = io.StringIO()
141139
with redirect_stderr(stream):
142-
testmod(failure_cases_2,
143-
strategy=[failure_cases_2.func_name_error], config=config)
140+
_testmod(failure_cases_2,
141+
strategy=[failure_cases_2.func_name_error], config=config)
144142

145143
stream.seek(0)
146144
output = stream.read()

0 commit comments

Comments
 (0)