From c72c03890c8bf75fa5c1a0aed7897e1efbdeed3d Mon Sep 17 00:00:00 2001 From: Bob Girard Date: Tue, 13 Jan 2015 11:55:31 -0700 Subject: [PATCH] Add detailed test coverage console report * Add a detailed console report to the 'test_coverage' command output * Expand the precision of all coverage percentages to two decimal places * Print the location of the HTML coverage report at the end of the console report --- .coveragerc | 7 +++++++ plinth/tests/coverage/test_coverage.py | 23 +++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 000000000..aca3e05cf --- /dev/null +++ b/.coveragerc @@ -0,0 +1,7 @@ +# .coveragerc -- specifies execution options for coverage.py + +[run] +branch = True + +[report] +precision = 2 diff --git a/plinth/tests/coverage/test_coverage.py b/plinth/tests/coverage/test_coverage.py index c5657558e..b16e10c17 100644 --- a/plinth/tests/coverage/test_coverage.py +++ b/plinth/tests/coverage/test_coverage.py @@ -3,7 +3,7 @@ # # This file is part of Plinth. # -# Dervied from code sample at: +# Derived from code sample at: # http://jeetworks.org/adding-test-code-coverage-analysis-to-a-python-projects-setup-command/ # # Copyright 2009 Jeet Sukumaran and Mark T. Holder. @@ -69,7 +69,8 @@ class TestCoverageCommand(setuptools.Command): self.distribution.install_requires) if self.distribution.tests_require: - self.distribution.fetch_build_eggs(self.distribution.tests_require) + self.distribution.fetch_build_eggs( + self.distribution.tests_require) # Erase any existing HTML report files try: @@ -88,17 +89,23 @@ class TestCoverageCommand(setuptools.Command): # Run the coverage analysis runner = unittest.TextTestRunner() import coverage - cov = coverage.coverage(auto_data=True, branch=True, + cov = coverage.coverage(auto_data=True, config_file=True, source=SOURCE_DIRS, omit=FILES_TO_OMIT) cov.erase() # Erase existing coverage data file cov.start() runner.run(test_suite) cov.stop() - # Generate an HTML report and print overall coverage + # Generate an HTML report html_report_title = 'FreedomBox:Plinth -- Test Coverage as of ' + \ time.strftime('%x %X %Z') - _coverage = cov.html_report(directory=COVERAGE_REPORT_DIR, - omit=FILES_TO_OMIT, - title=html_report_title) - print('\nOverall test coverage: {0:.2f} %\n'.format(_coverage)) + cov.html_report(directory=COVERAGE_REPORT_DIR, omit=FILES_TO_OMIT, + title=html_report_title) + + # Print a detailed console report with the overall coverage percentage + print() + cov.report(omit=FILES_TO_OMIT) + + # Print the location of the HTML report + print('\nThe HTML coverage report is located at {}.'.format( + COVERAGE_REPORT_DIR))