diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-08-16 14:19:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-16 14:19:17 -0500 |
commit | 26c79664d2edd48e1777cc4b31ecb952e2ec30d5 (patch) | |
tree | 0dfe2a03d716fbd8116d3d02150dc453bf741a26 /numpy/conftest.py | |
parent | 663094532de48e131793faaa0ba06eb7c051ab47 (diff) | |
parent | 3deb8fa4f4d25e434c86188593f95dfc2fed041c (diff) | |
download | numpy-26c79664d2edd48e1777cc4b31ecb952e2ec30d5.tar.gz |
Merge pull request #9574 from pv/fpflag
BUG: deal with broken hypot() for MSVC on win32
Diffstat (limited to 'numpy/conftest.py')
-rw-r--r-- | numpy/conftest.py | 54 |
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)) |