-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.py
77 lines (58 loc) · 1.8 KB
/
manage.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
69
70
71
72
73
74
75
76
77
import os
import unittest
import coverage
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from app import blueprint
from app.main import create_app, db
from app.main.model import user, blacklist
app = create_app(os.getenv('BOILERPLATE_ENV') or 'dev')
app.register_blueprint(blueprint)
app.app_context().push()
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
@manager.command
def run():
app.run()
@manager.command
def cov():
"""
Runs the unit tests and generates a coverage report on success.
While the application is running, you can run the following command in a new terminal:
'docker-compose run --rm flask python manage.py cov' to run all the tests in the
'tests' directory. If all the tests pass, it will generate a coverage report.
:return int: 0 if all tests pass, 1 if not
"""
# Defines which parts of the code to include and omit when calculating code coverage.
COV = coverage.coverage(
branch=True,
include='app/main/*',
omit=[
'app/test/*'
],
data_file='.coverage'
)
COV.start()
tests = unittest.TestLoader().discover('app/test', pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
#COV.html_report()
#COV.erase()
return 0
else:
return 1
@manager.command
def test():
"""Runs the unit tests."""
tests = unittest.TestLoader().discover('app/test', pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
if __name__ == '__main__':
manager.run()