Skip to content

Commit

Permalink
Fixes #22 for late coverage.py init
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturSpirin committed Oct 27, 2019
1 parent c0943ec commit e462bf5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="test_junkie",
version="0.7a7",
version="0.7a8",
author="Artur Spirin",
author_email="[email protected]",
description="Modern Testing Framework",
Expand Down
43 changes: 23 additions & 20 deletions test_junkie/cli/cli_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def __init__(self, sources, ignore, suites, **kwargs):
self.requested_suites = suites
self.__config = Config(config_name=CliConstants.TJ_CONFIG_NAME if
self.__execution_config == Undefined else self.__execution_config)
self.coverage = None
if self.code_cov:
import coverage
if self.cov_rcfile is not None:
self.coverage = coverage.Coverage(omit="*{sep}test_junkie{sep}*".format(sep=os.sep),
config_file=self.cov_rcfile)
else:
self.coverage = coverage.Coverage(omit="*{sep}test_junkie{sep}*".format(sep=os.sep))
self.coverage.start()

@property
def sources(self):
Expand Down Expand Up @@ -247,15 +256,6 @@ def tags():
if self.suites:
print("[{status}] Running tests ...\n"
.format(status=CliUtils.format_color_string(value="INFO", color="blue")))
if self.code_cov:
import coverage

if self.cov_rcfile is not None:
cov = coverage.Coverage(omit="*{sep}test_junkie{sep}*".format(sep=os.sep),
config_file=self.cov_rcfile)
else:
cov = coverage.Coverage(omit="*{sep}test_junkie{sep}*".format(sep=os.sep))
cov.start()
try:
runner = Runner(suites=self.suites,
html_report=args.html_report,
Expand All @@ -278,15 +278,18 @@ def tags():
CliUtils.print_color_traceback()
exit(120)
finally:
if self.code_cov:
cov.stop()
cov.save()
if self.code_cov:
try:
cov.report(show_missing=True, skip_covered=True)
print("[{status}] TJ uses Coverage.py. Control it with --cov-rcfile, "
"see {link}".format(status=CliUtils.format_color_string(value="TIP", color="blue"),
link=DocumentationLinks.COVERAGE_CONFIG_FILE))
except coverage.misc.CoverageException:
pass
if self.coverage is not None:
self.coverage.stop()
self.coverage.save()
import coverage
try:
print("[{status}] Code coverage report:".format(
status=CliUtils.format_color_string(value="INFO", color="blue")))
self.coverage.report(show_missing=True, skip_covered=True)
print("[{status}] TJ uses Coverage.py. Control it with --cov-rcfile, "
"see {link}".format(status=CliUtils.format_color_string(value="TIP", color="blue"),
link=DocumentationLinks.COVERAGE_CONFIG_FILE))
except coverage.misc.CoverageException:
CliUtils.print_color_traceback()
exit(120)
return

0 comments on commit e462bf5

Please sign in to comment.