Merge branch 'master' into feature/pytest
[aubio.git] / python / tests / _tools.py
1 """
2 This file imports test methods from different testing modules, in this
3 order:
4
5     - try importing 'pytest'
6     - if it fails, fallback to 'numpy.testing'
7
8 Nose2 support was removed because of lacking assertWarns on py2.7.
9
10 """
11
12 import sys
13
14 _has_pytest = False
15
16 # check if we have pytest
17 try:
18     import pytest
19     parametrize = pytest.mark.parametrize
20     assert_raises = pytest.raises
21     assert_warns = pytest.warns
22     skipTest = pytest.skip
23     _has_pytest = True
24     def run_module_suite():
25         import sys, pytest
26         pytest.main(sys.argv)
27 except:
28     pass
29
30 # otherwise fallback on numpy.testing
31 if not _has_pytest:
32     from numpy.testing import dec, assert_raises, assert_warns
33     from numpy.testing import SkipTest
34     parametrize = dec.parametrize
35     def skipTest(msg):
36         raise SkipTest(msg)
37     from numpy.testing import run_module_suite
38
39 # always use numpy's assert_equal
40 import numpy
41 assert_equal = numpy.testing.assert_equal