History

[tests] add checks.py, selects testing module

Paul Brossier committed 8 years ago

Commit 98972b91 parent 0ed04051 file · +50 −0Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/tests/checks.py+50−0
@@ -0,0 +1,50 @@
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 print ('using nose2')
25
26# otherwise, check if we have pytest
27if not _has_nose2:
28 try:
29 import pytest
30 parametrize = pytest.mark.parametrize
31 _has_pytest = True
32 assert_raises = pytest.raises
33 assert_warns = pytest.warns
34 skipTest = pytest.skip
35 print ('using pytest')
36 except:
37 pass
38
39# otherwise fallback on numpy.testing
40if not _has_pytest and not _has_nose2:
41 from numpy.testing import dec, assert_raises, assert_warns
42 from numpy.testing import SkipTest
43 parametrize = dec.parametrize
44 def skipTest(msg):
45 raise SkipTest(msg)
46 print ('using numpy')
47
48# always use numpy's assert_equal
49import numpy
50assert_equal = numpy.testing.assert_equal

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t