source: python/tests/_tools.py @ 01d56c1

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 01d56c1 was 01d56c1, checked in by Paul Brossier <piem@piem.org>, 5 years ago

[tests] update _tools

  • Property mode set to 100644
File size: 1.2 KB
Line 
1"""
2This file imports test methods from different testing modules, in this
3order:
4
5    - if 'nose2' is found in the list of loaded module, use it
6    - otherwise, try using 'pytest'
7    - if that also fails, fallback to 'numpy.testing'
8"""
9
10import sys
11
12_has_pytest = False
13_has_nose2 = False
14
15# if nose2 has already been imported, use it
16if 'nose2' in sys.modules:
17    from nose2.tools import params, such
18    def parametrize(argnames, argvalues):
19        return params(*argvalues)
20    assert_raises = such.helper.assertRaises
21    assert_warns = such.helper.assertWarns
22    skipTest = such.helper.skipTest
23    _has_nose2 = True
24
25# otherwise, check if we have pytest
26if not _has_nose2:
27    try:
28        import pytest
29        parametrize = pytest.mark.parametrize
30        assert_raises = pytest.raises
31        assert_warns = pytest.warns
32        skipTest = pytest.skip
33        _has_pytest = True
34    except:
35        pass
36
37# otherwise fallback on numpy.testing
38if not _has_pytest and not _has_nose2:
39    from numpy.testing import dec, assert_raises, assert_warns
40    from numpy.testing import SkipTest
41    parametrize = dec.parametrize
42    def skipTest(msg):
43        raise SkipTest(msg)
44
45# always use numpy's assert_equal
46import numpy
47assert_equal = numpy.testing.assert_equal
Note: See TracBrowser for help on using the repository browser.