-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_coverage.py
More file actions
60 lines (45 loc) · 1.62 KB
/
run_coverage.py
File metadata and controls
60 lines (45 loc) · 1.62 KB
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
import os
import subprocess
import sys
# Do not ever rename this file to coverage.py as it creates an infinite loop.
# This script must run from the root of your project.
if sys.platform != 'win32':
raise Exception('Only the Windows platform is supported for this script.')
virtual_env = os.path.join(os.path.dirname(__file__), 'venv', 'Scripts', 'activate')
virtual_env_alternate = os.path.join(os.path.dirname(__file__), '.venv', 'Scripts', 'activate')
if os.path.isfile(virtual_env):
activate_virtualenv_cmd = virtual_env
elif os.path.isfile(virtual_env_alternate):
activate_virtualenv_cmd = virtual_env_alternate
else:
raise Exception(f'Virtual environment "{virtual_env}" or "{virtual_env_alternate}" not found.')
pip_install_coverage_cmd = 'pip install coverage'
print('Running coverage with tests ...\n')
omits = (
'*/system/*',
'*/tests/*',
'*/migrations/*',
'*/static/*',
'*/.venv/*',
'apps.py',
'__init__.py',
'manage.py',
'automation.py',
'run_coverage.py',
'setup.py',
)
coverage_run_cmd = f'coverage run --branch --source=. --omit={",".join(omits)} -m unittest discover tests'
html_directory = '.coverage_html_report'
coverage_html_cmd = f'coverage html --directory={html_directory}'
coverage_erase_cmd = f'coverage erase'
open_browser_cmd = f'start "" "{os.path.dirname(__file__)}/{html_directory}/index.html"'
cmd_call = (
f'call {activate_virtualenv_cmd}'
f' & {pip_install_coverage_cmd}'
f' & {coverage_run_cmd}'
f' & {coverage_html_cmd}'
f' & {coverage_erase_cmd}'
f' & {open_browser_cmd}'
)
subprocess.run(cmd_call, shell=True)
print('\nDone!')