def test(coverage=False):
"""Run the unit tests."""
if coverage and not os.environ.get('FLASK_COVERAGE'):
os.environ['FLASK_COVERAGE'] = '1'
os.execvp(sys.executable, [sys.executable] + sys.argv)
testresult = TextTestRunner(verbosity=2).run(TestLoader().discover('tests'))
if cov:
cov.stop()
cov.save()
print('Coverage Summary:')
cov.report()
covdir = app.config.get('COVERAGE_DIRECTORY', '')
if covdir:
covdir = os.path.join(covdir, datetime.utcnow().strftime('%Y-%m-%d-%H-%M-%S'))
if not os.path.exists(covdir):
os.makedirs(covdir)
cov.html_report(directory=covdir)
print('Coverage HTML version: file://{}/index.html'.format(covdir))
cov.erase()
if len(testresult.failures) + len(testresult.errors) > 0:
sys.exit(1)
评论列表
文章目录