summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2009-04-24 21:23:39 +0000
committerPauli Virtanen <pav@iki.fi>2009-04-24 21:23:39 +0000
commit3af85933cfc992430350fc1daaa991720b70ed82 (patch)
treebaabfe058cd4aa509e72e0244ceed7c3f4443d7e /numpy/testing/utils.py
parent0d5e8c8e97e3075b1ccb2c257c998b63fad80903 (diff)
downloadnumpy-3af85933cfc992430350fc1daaa991720b70ed82.tar.gz
Make testing.rundocs to raise error on failures; otherwise Nose hides them
Also drop Python < 2.4 compatibility.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index b55b900f7..ba9b16b18 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -649,8 +649,10 @@ def assert_string_equal(actual, desired):
raise AssertionError(msg)
-def rundocs(filename=None):
- """ Run doc string tests found in filename.
+def rundocs(filename=None, raise_on_error=True):
+ """Run doc string tests found in file.
+
+ By default raises AssertionError on failure.
"""
import doctest, imp
if filename is None:
@@ -663,14 +665,21 @@ def rundocs(filename=None):
m = imp.load_module(name, file, pathname, description)
finally:
file.close()
- if sys.version[:3]<'2.4':
- doctest.testmod(m, verbose=False)
+
+ tests = doctest.DocTestFinder().find(m)
+ runner = doctest.DocTestRunner(verbose=False)
+
+ msg = []
+ if raise_on_error:
+ out = lambda s: msg.append(s)
else:
- tests = doctest.DocTestFinder().find(m)
- runner = doctest.DocTestRunner(verbose=False)
- for test in tests:
- runner.run(test)
- return
+ out = None
+
+ for test in tests:
+ runner.run(test, out=out)
+
+ if runner.failures > 0 and raise_on_error:
+ raise AssertionError("Some doctests failed:\n%s" % "\n".join(msg))
def raises(*args,**kwargs):