-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5cecbd
commit ca278c2
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
import os | ||
|
||
COV = None | ||
if os.environ.get('FLASK_COVERAGE'): | ||
import coverage | ||
COV = coverage.coverage(branch=True, include='app/*') | ||
COV.start() | ||
|
||
import sys | ||
import click | ||
from flask_migrate import Migrate | ||
from app import create_app, db | ||
|
@@ -15,12 +23,29 @@ def make_shell_context(): | |
|
||
|
||
@app.cli.command() | ||
@click.option('--coverage/--no-coverage', default=False, | ||
help='Run tests under code coverage.') | ||
@click.argument('test_names', nargs=-1) | ||
def test(test_names): | ||
def test(coverage, test_names): | ||
"""Run the unit tests.""" | ||
if coverage and not os.environ.get('FLASK_COVERAGE'): | ||
import subprocess | ||
os.environ['FLASK_COVERAGE'] = '1' | ||
sys.exit(subprocess.call(sys.argv)) | ||
|
||
import unittest | ||
if test_names: | ||
tests = unittest.TestLoader().loadTestsFromNames(test_names) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
miguelgrinberg
Author
Owner
|
||
else: | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
-r common.txt | ||
certifi==2017.7.27.1 | ||
chardet==3.0.4 | ||
coverage==4.4.1 | ||
faker==0.7.18 | ||
httpie==0.9.9 | ||
idna==2.5 | ||
|
Hi Miguel,
With
loadTestsFromNames
, would the correct usage to run only a subset of tests, for example, test_home_page beflask test test_home_page
? I get a ModuleNotFoundError when I use it like this, and I am not sure what I'm missing.Any pointers will be welcome. Thanks