Skip to content

Commit 8c58877

Browse files
committed
feat: add coverage
1 parent a3263d6 commit 8c58877

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

‎services/users/.dockerignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Dockerfile-dev
2-
Dockerfile-prod
2+
Dockerfile-prod
3+
venv

‎services/users/manage.py‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
import unittest
1+
import unittest, coverage
22
from flask.cli import FlaskGroup
33
from project import create_app, db
44
from project.api.models import User
55

6+
7+
COV = coverage.coverage(
8+
branch=True,
9+
include="project/*",
10+
omit=[
11+
"project/test/*",
12+
"project/config.py",
13+
],
14+
)
15+
16+
COV.start()
17+
618
app = create_app()
719
cli = FlaskGroup(create_app=create_app)
820

@@ -32,5 +44,23 @@ def seed_db():
3244
db.session.commit()
3345

3446

47+
@cli.command()
48+
def cov():
49+
"""
50+
Runs the unit tests coverage
51+
"""
52+
tests = unittest.TestLoader().discover("project/tests")
53+
result = unittest.TextTestRunner(verbosity=2).run(tests)
54+
if result.wasSuccessful():
55+
COV.stop()
56+
COV.save()
57+
print("Coverage Summary:")
58+
COV.report()
59+
COV.html_report()
60+
COV.erase()
61+
return 0
62+
return 1
63+
64+
3565
if __name__ == "__main__":
3666
cli()

‎services/users/requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ SQLAlchemy==2.0.4
1313
typing-extensions==4.5.0
1414
Werkzeug==2.2.3
1515
zipp==3.15.0
16+
coverage==7.2.1

0 commit comments

Comments
 (0)