Skip to content

Commit 791a9a0

Browse files
author
Benjamin Moody
committed
When running nosetests, raise exceptions for arithmetic errors.
nosetests will invoke the functions setup_module() and teardown_module(), if defined, before and after running all test cases within the module. In general, numpy arithmetic errors (e.g. integer or floating-point overflow, or division by zero) should not happen under normal circumstances, and the package should neither assume that these errors will raise an exception, nor assume that they won't. Therefore, while running the test suite, set the numpy error handling mode to "raise" so the test will fail if such an error occurs.
1 parent 6be3066 commit 791a9a0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import numpy as np
2+
3+
4+
_np_error_state = {}
5+
6+
7+
def setup_module():
8+
# Raise exceptions for arithmetic errors, except underflow
9+
global _np_error_state
10+
_np_error_state = np.seterr()
11+
np.seterr('raise', under='ignore')
12+
13+
14+
def teardown_module():
15+
# Restore original error handling state
16+
np.seterr(**_np_error_state)

0 commit comments

Comments
 (0)