Skip to content

Commit

Permalink
Chapter 15: Coverage metrics (15a)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Nov 5, 2015
1 parent 3a46cc1 commit 01c4f97
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env python
import os
COV = None
if os.environ.get('FLASK_COVERAGE'):
import coverage
COV = coverage.coverage(branch=True, include='app/*')
COV.start()

from app import create_app, db
from app.models import User, Follow, Role, Permission, Post, Comment
from flask.ext.script import Manager, Shell
Expand All @@ -18,11 +24,25 @@ def make_shell_context():


@manager.command
def test():
def test(coverage=False):
"""Run the unit tests."""
if coverage and not os.environ.get('FLASK_COVERAGE'):
import sys
os.environ['FLASK_COVERAGE'] = '1'
os.execvp(sys.executable, [sys.executable] + sys.argv)
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
if COV:
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
basedir = os.path.abspath(os.path.dirname(__file__))
covdir = os.path.join(basedir, 'tmp/coverage')
COV.html_report(directory=covdir)
print('HTML version: file://%s/index.html' % covdir)
COV.erase()


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
ForgeryPy==0.1
Pygments==1.6
colorama==0.2.7
coverage==3.7.1
httpie==0.7.2
requests==2.1.0

0 comments on commit 01c4f97

Please sign in to comment.