Run doctests found in the given file. By default `rundocs` raises an AssertionError on failure. Parameters ---------- filename : str The path to the file for which the doctests are run. raise_on_error : bool Whether to raise an AssertionError when a doctest
(filename=None, raise_on_error=True)
| 1191 | |
| 1192 | |
| 1193 | def rundocs(filename=None, raise_on_error=True): |
| 1194 | """ |
| 1195 | Run doctests found in the given file. |
| 1196 | |
| 1197 | By default `rundocs` raises an AssertionError on failure. |
| 1198 | |
| 1199 | Parameters |
| 1200 | ---------- |
| 1201 | filename : str |
| 1202 | The path to the file for which the doctests are run. |
| 1203 | raise_on_error : bool |
| 1204 | Whether to raise an AssertionError when a doctest fails. Default is |
| 1205 | True. |
| 1206 | |
| 1207 | Notes |
| 1208 | ----- |
| 1209 | The doctests can be run by the user/developer by adding the ``doctests`` |
| 1210 | argument to the ``test()`` call. For example, to run all tests (including |
| 1211 | doctests) for `numpy.lib`: |
| 1212 | |
| 1213 | >>> np.lib.test(doctests=True) # doctest: +SKIP |
| 1214 | """ |
| 1215 | from numpy.distutils.misc_util import exec_mod_from_location |
| 1216 | import doctest |
| 1217 | if filename is None: |
| 1218 | f = sys._getframe(1) |
| 1219 | filename = f.f_globals['__file__'] |
| 1220 | name = os.path.splitext(os.path.basename(filename))[0] |
| 1221 | m = exec_mod_from_location(name, filename) |
| 1222 | |
| 1223 | tests = doctest.DocTestFinder().find(m) |
| 1224 | runner = doctest.DocTestRunner(verbose=False) |
| 1225 | |
| 1226 | msg = [] |
| 1227 | if raise_on_error: |
| 1228 | out = lambda s: msg.append(s) |
| 1229 | else: |
| 1230 | out = None |
| 1231 | |
| 1232 | for test in tests: |
| 1233 | runner.run(test, out=out) |
| 1234 | |
| 1235 | if runner.failures > 0 and raise_on_error: |
| 1236 | raise AssertionError("Some doctests failed:\n%s" % "\n".join(msg)) |
| 1237 | |
| 1238 | |
| 1239 | def check_support_sve(): |
nothing calls this directly
no test coverage detected