-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
68 lines (52 loc) · 1.36 KB
/
runtests.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
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8
from __future__ import unicode_literals, absolute_import
import os
import sys
import subprocess
import pytest
PYTEST_ARGS = ['--tb=short', '-q', '-s', '-rw']
FLAKE8_ARGS = ['app', 'tests']
sys.path.append(os.path.dirname(__file__))
def flake8_main(args):
print('Running lint tests...')
flake8 = subprocess.call(['flake8'] + args)
print('\033[91m' + 'Lint flake8 failed' + '\033[0m' if flake8 else
'\033[92m' + 'Lint flake8 passed' + '\033[0m')
return flake8
def exit_if_failed(func):
if func:
sys.exit(func)
if __name__ == '__main__':
run_lint = True
run_pytest = True
# No lint
try:
sys.argv.remove('--nolint')
except ValueError:
run_lint = True
else:
run_lint = False
# Lint only
try:
sys.argv.remove('--lintonly')
except ValueError:
run_pytest = True
else:
run_pytest = False
# Coverage option
if run_pytest:
try:
sys.argv.remove('--coverage')
except ValueError:
pass
else:
PYTEST_ARGS += [
'--cov-report', 'html',
'--cov', 'app']
# Run flake8 lint
if run_lint:
exit_if_failed(flake8_main(FLAKE8_ARGS))
# Run pytest
if run_pytest:
exit_if_failed(pytest.main(PYTEST_ARGS))