我正在努力让coverage.py与我的 Flask 应用程序一起工作。
我正在尝试通过子流程说明进行设置:http: //nedbatchelder.com/code/coverage/subprocess.html
在我的create_app()
函数(这是一个应用程序工厂)中,我有以下内容:
if settings.FLASK_ENV == 'TEST':
coverage.process_startup()
在我的测试套件中,我有以下内容:
# Need to add the 'COVERAGE_PROCESS_START' environment variable for subprocesses
if os.getenv('COVERAGE'):
test_env['COVERAGE_PROCESS_START'] = 'tests/.coveragerc'
test_env['FLASK_ENV'] = 'TEST'
test_process = subprocess.Popen(["gunicorn", "run_server:app", '--log-level=warning', '-w 1', '-b {host}:{port}'.format(host='127.0.0.1',port=port())],
env=test_env)
在我的测试结束时,我做...
coverage.save()
coverage.combine()
percent_covered = coverage.html_report(directory='covhtml')
print "Percent Covered: {}".format(percent_covered)
coverage.stop()
但唉..报道似乎没有合并
ls -alt
注意:如果我在目录中看到这样的列表,则在调用 combine 之前...
-rw-r--r-- .coverage.Jonathans-MacBook-Pro-3.local.49352.501916
-rw-r--r-- .coverage.Jonathans-MacBook-Pro-3.local.49352.931352
为了完整起见,我的 .coveragerc 很简单:
[run]
parallel = True
希望能指出正确的方向——谢谢!