/
__init__.py
47 lines (38 loc) · 1.28 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
import os
import sys
from typing import List, Optional, Sequence, Union
from arch.utility.cov import cov_nw
PKG = os.path.dirname(os.path.dirname(__file__))
def test(
extra_args: Optional[Union[str, Sequence[str]]] = None, exit: bool = True
) -> None:
"""
Test runner that allows testing of installed package.
Exists with test status code upon completion.
Parameters
----------
extra_args : {str, list[str]}, default None
Extra arguments to pass to pytest. Default options are --tb=short
and --disable-pytest-warnings. Providing extra_args overwrites the
defaults with the user-provided arguments.
"""
try:
import pytest
except ImportError:
raise ImportError("Need pytest to run tests")
cmd: List[str] = []
default_args = ["--tb=short", "--disable-pytest-warnings"]
if extra_args is None:
extra_args_lst = default_args
elif isinstance(extra_args, str):
extra_args_lst = [extra_args]
else: # extra_args is not None
extra_args_lst = list(extra_args)
if extra_args_lst:
cmd = extra_args_lst[:]
cmd = [PKG] + cmd
print("running: pytest {}".format(" ".join(cmd)))
status = pytest.main(cmd)
if exit:
sys.exit(status)
__all__ = ["cov_nw", "test"]