本文整理汇总了Python中coverage.Coverage.start方法的典型用法代码示例。如果您正苦于以下问题:Python Coverage.start方法的具体用法?Python Coverage.start怎么用?Python Coverage.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.Coverage
的用法示例。
在下文中一共展示了Coverage.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_coverage
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def run_coverage(self, test_name):
cov = Coverage(source=self.config.source, omit=self.config.omit)
cov.start()
self.map_test(test_name)
cov.stop()
return cov.get_data()
示例2: run_tests
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def run_tests(self):
" Run coverage on unit test "
# need to import here cause we are in a venv
import six
from coverage import Coverage
coverage = Coverage()
coverage.start()
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
if six.PY3 and getattr(self.distribution, 'use_2to3', False):
module = self.test_suite.split('.')[0]
if module in _namespace_packages:
del_modules = []
if module in sys.modules:
del_modules.append(module)
module += '.'
for name in sys.modules:
if name.startswith(module):
del_modules.append(name)
list(map(sys.modules.__delitem__, del_modules))
unittest_main(
None, None, self._argv,
testLoader=self._resolve_as_ep(self.test_loader),
testRunner=self._resolve_as_ep(self.test_runner),
exit=False,
)
coverage.stop()
coverage.save()
coverage.report(show_missing=False)
示例3: run_tests
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def run_tests(context, app=None, module=None, doctype=None, test=(),
driver=None, profile=False, coverage=False, junit_xml_output=False, ui_tests = False,
doctype_list_path=None, skip_test_records=False, skip_before_tests=False, failfast=False):
"Run tests"
import frappe.test_runner
tests = test
site = get_site(context)
frappe.init(site=site)
frappe.flags.skip_before_tests = skip_before_tests
frappe.flags.skip_test_records = skip_test_records
if coverage:
# Generate coverage report only for app that is being tested
source_path = os.path.join(get_bench_path(), 'apps', app or 'frappe')
cov = Coverage(source=[source_path], omit=['*.html', '*.js', '*.css'])
cov.start()
ret = frappe.test_runner.main(app, module, doctype, context.verbose, tests=tests,
force=context.force, profile=profile, junit_xml_output=junit_xml_output,
ui_tests = ui_tests, doctype_list_path = doctype_list_path, failfast=failfast)
if coverage:
cov.stop()
cov.save()
if len(ret.failures) == 0 and len(ret.errors) == 0:
ret = 0
if os.environ.get('CI'):
sys.exit(ret)
示例4: run_tests
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def run_tests(self):
from illume import config
from coverage import Coverage
config.setenv("test")
from pytest import main
from illume.util import remove_or_ignore_dir
from logging import basicConfig, DEBUG
basicConfig(level=DEBUG, filename="illume-test.log")
project_root = config.get("PROJECT_ROOT")
data_dir = config.get("DATA_DIR")
cov_config_dir = os.path.join(project_root, '.coveagerc')
cov = Coverage(config_file=cov_config_dir)
# Remvoe data directory in case tests failed to complete last time.
remove_or_ignore_dir(data_dir)
cov.start()
exit_code = main(shlex.split(self.pytest_args or ""))
cov.stop()
cov.xml_report()
# Remove data directory if tests passed successfully. Keep it around
# if tests failed so the developer can troubleshoot the problem.
if exit_code == 0:
remove_or_ignore_dir(data_dir)
sys.exit(exit_code)
示例5: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def _bootstrap(self):
from coverage import Coverage
cov = Coverage(data_suffix=True)
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例6: run_with_coverage
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def run_with_coverage(run):
from coverage import Coverage
coverage = Coverage()
coverage.start()
apply(run)
coverage.end()
coverage.result(['../core/%s' % prefix,])
示例7: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage
cov = Coverage(data_suffix=True)
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例8: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage
rcfile = getattr(multiprocessing, PATCHED_MARKER)
cov = Coverage(data_suffix=True, config_file=rcfile)
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例9: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage # avoid circular import
rcfile = os.environ[COVERAGE_RCFILE_ENV]
cov = Coverage(data_suffix=True, config_file=rcfile)
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例10: CoverageContext
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
class CoverageContext(object):
def __init__(self):
from coverage import Coverage
self._cov = Coverage(cover_pylib=False)
self._cov.start()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self._cov.stop()
示例11: run
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def run(self):
from coverage import Coverage
cov = Coverage(source=self.distribution.packages)
cov.start()
super().run()
cov.stop()
cov.xml_report()
cov.html_report()
示例12: run
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def run(self):
import pytest
cov = Coverage()
cov.erase()
cov.start()
result = pytest.main()
cov.stop()
cov.save()
cov.html_report(directory="covhtml")
sys.exit(int(bool(len(result.failures) > 0 or len(result.errors) > 0)))
示例13: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage
coverage_config = getattr(multiprocessing, PATCHED_MARKER)
coverage_config.parallel = True
cov = Coverage()
cov.config = coverage_config
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例14: run_test_suite
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def run_test_suite():
cov = Coverage(config_file=True)
cov.erase()
cov.start()
# Announce the test suite
sys.stdout.write(colored(text="\nWelcome to the ", color="magenta", attrs=["bold"]))
sys.stdout.write(colored(text="python-doc-inherit", color="green", attrs=["bold"]))
sys.stdout.write(colored(text=" test suite.\n\n", color="magenta", attrs=["bold"]))
# Announce test run
print(colored(text="Step 1: Running unit tests.\n", color="yellow", attrs=["bold"]))
test_suite = TestLoader().discover(str(Path("tests").absolute()))
result = TextTestRunner(verbosity=1).run(test_suite)
if not result.wasSuccessful():
sys.exit(len(result.failures) + len(result.errors))
# Announce coverage run
print(colored(text="\nStep 2: Generating coverage results.\n", color="yellow", attrs=["bold"]))
cov.stop()
percentage = round(cov.report(show_missing=True), 2)
cov.html_report(directory='cover')
cov.save()
if percentage < TESTS_THRESHOLD:
print(colored(text="YOUR CHANGES HAVE CAUSED TEST COVERAGE TO DROP. " +
"WAS {old}%, IS NOW {new}%.\n".format(old=TESTS_THRESHOLD, new=percentage),
color="red", attrs=["bold"]))
sys.exit(1)
# Announce flake8 run
sys.stdout.write(colored(text="\nStep 3: Checking for pep8 errors.\n\n", color="yellow", attrs=["bold"]))
print("pep8 errors:")
print("----------------------------------------------------------------------")
from subprocess import call
flake_result = call(["flake8", ".", "--count"])
if flake_result != 0:
print("pep8 errors detected.")
print(colored(text="\nYOUR CHANGES HAVE INTRODUCED PEP8 ERRORS!\n", color="red", attrs=["bold"]))
sys.exit(flake_result)
else:
print("None")
# Announce success
print(colored(text="\nTests completed successfully with no errors. Congrats!", color="green", attrs=["bold"]))
示例15: with_coverage
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import start [as 别名]
def with_coverage(f, source, *, report=True, data=False):
cov = Coverage(source=[source])
cov.start()
try:
exit_code = f()
finally:
cov.stop()
if not exit_code:
if report:
print() # Print blank line.
cov.report(show_missing=False)
cov.html_report()
if data:
cov.save()
return exit_code