summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2017-08-16 18:15:18 +0200
committerPauli Virtanen <pav@iki.fi>2017-08-16 20:39:14 +0200
commit3deb8fa4f4d25e434c86188593f95dfc2fed041c (patch)
tree0dfe2a03d716fbd8116d3d02150dc453bf741a26
parentb5f472d450522a701fa526f8c85f7eb467d65c1a (diff)
downloadpython-numpy-3deb8fa4f4d25e434c86188593f95dfc2fed041c.tar.gz
python-numpy-3deb8fa4f4d25e434c86188593f95dfc2fed041c.tar.bz2
python-numpy-3deb8fa4f4d25e434c86188593f95dfc2fed041c.zip
TST: add FPU mode check also for pytest
-rw-r--r--numpy/conftest.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/numpy/conftest.py b/numpy/conftest.py
new file mode 100644
index 000000000..ea4197049
--- /dev/null
+++ b/numpy/conftest.py
@@ -0,0 +1,54 @@
+"""
+Pytest configuration and fixtures for the Numpy test suite.
+"""
+from __future__ import division, absolute_import, print_function
+
+import warnings
+import pytest
+
+from numpy.core.multiarray_tests import get_fpu_mode
+
+
+_old_fpu_mode = None
+_collect_results = {}
+
+
+@pytest.hookimpl()
+def pytest_itemcollected(item):
+ """
+ Check FPU precision mode was not changed during test collection.
+
+ The clumsy way we do it here is mainly necessary because numpy
+ still uses yield tests, which can execute code at test collection
+ time.
+ """
+ global _old_fpu_mode
+
+ mode = get_fpu_mode()
+
+ if _old_fpu_mode is None:
+ _old_fpu_mode = mode
+ elif mode != _old_fpu_mode:
+ _collect_results[item] = (_old_fpu_mode, mode)
+ _old_fpu_mode = mode
+
+
+@pytest.fixture(scope="function", autouse=True)
+def check_fpu_mode(request):
+ """
+ Check FPU precision mode was not changed during the test.
+ """
+ old_mode = get_fpu_mode()
+ yield
+ new_mode = get_fpu_mode()
+
+ if old_mode != new_mode:
+ raise AssertionError("FPU precision mode changed from {0:#x} to {1:#x}"
+ " during the test".format(old_mode, new_mode))
+
+ collect_result = _collect_results.get(request.node)
+ if collect_result is not None:
+ old_mode, new_mode = collect_result
+ raise AssertionError("FPU precision mode changed from {0:#x} to {1:#x}"
+ " when collecting the test".format(old_mode,
+ new_mode))