/
__init__.py
57 lines (44 loc) · 1.91 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import print_function
__docformat__ = 'restructuredtext'
from distutils.version import LooseVersion
import os
import sys
from warnings import simplefilter
from statsmodels.tools.sm_exceptions import (ConvergenceWarning, CacheWriteWarning,
IterationLimitWarning, InvalidTestWarning)
simplefilter("always", (ConvergenceWarning, CacheWriteWarning,
IterationLimitWarning, InvalidTestWarning))
debug_warnings = False
if debug_warnings:
import sys, warnings
warnings.simplefilter("default")
# use the following to raise an exception for debugging specific warnings
# warnings.filterwarnings("error", message=".*integer.*")
if (sys.version_info[0] >= 3):
# ResourceWarning doesn't exist in python 2
# we have currently many ResourceWarnings in the datasets on python 3.4
warnings.simplefilter("ignore", ResourceWarning)
class PytestTester(object):
def __init__(self):
f = sys._getframe(1)
package_path = f.f_locals.get('__file__', None)
if package_path is None:
raise ValueError('Unable to determine path')
self.package_path = os.path.dirname(package_path)
self.package_name = f.f_locals.get('__name__', None)
def __call__(self, extra_args=None):
try:
import pytest
if not LooseVersion(pytest.__version__) >= LooseVersion('3.0'):
raise ImportError
extra_args = ['--tb=short','--disable-pytest-warnings'] if extra_args is None else extra_args
cmd = [self.package_path] + extra_args
print('Running pytest ' + ' '.join(cmd))
pytest.main(cmd)
except ImportError:
raise ImportError('pytest>=3 required to run the test')
test = PytestTester()
try:
from .version import version as __version__
except ImportError:
__version__ = 'not-yet-built'