mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-13 17:05:46 -06:00
tests: Add --coverage option to print a report
This commit is contained in:
parent
88f2d1abe0
commit
351ff1ae57
39
setup.py
39
setup.py
@ -356,11 +356,14 @@ class configure(Command):
|
||||
|
||||
|
||||
class TestBaseCommand(Command):
|
||||
user_options = [('debug', 'd', 'Show debug output')]
|
||||
boolean_options = ['debug']
|
||||
user_options = [
|
||||
('debug', 'd', 'Show debug output'),
|
||||
('coverage', 'c', 'Show coverage report')
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
self.debug = 0
|
||||
self.coverage = 0
|
||||
self._testfiles = []
|
||||
self._dir = os.getcwd()
|
||||
|
||||
@ -370,19 +373,24 @@ class TestBaseCommand(Command):
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
# Use system 'coverage' if available
|
||||
import coverage
|
||||
use_coverage = True
|
||||
use_cov = True
|
||||
except:
|
||||
use_coverage = False
|
||||
use_cov = False
|
||||
|
||||
|
||||
if use_cov:
|
||||
omit = ["/usr/*", "/*/tests/*"]
|
||||
cov = coverage.coverage(omit=omit)
|
||||
cov.erase()
|
||||
cov.start()
|
||||
|
||||
import tests as testsmodule
|
||||
testsmodule.cov = cov
|
||||
|
||||
tests = unittest.TestLoader().loadTestsFromNames(self._testfiles)
|
||||
t = unittest.TextTestRunner(verbosity=1)
|
||||
|
||||
if use_coverage:
|
||||
coverage.erase()
|
||||
coverage.start()
|
||||
|
||||
if hasattr(unittest, "installHandler"):
|
||||
try:
|
||||
unittest.installHandler()
|
||||
@ -394,11 +402,16 @@ class TestBaseCommand(Command):
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(1)
|
||||
|
||||
if use_coverage:
|
||||
coverage.stop()
|
||||
if use_cov:
|
||||
cov.stop()
|
||||
cov.save()
|
||||
|
||||
err = int(bool(len(result.failures) > 0 or
|
||||
len(result.errors) > 0))
|
||||
if not err and use_cov and self.coverage:
|
||||
cov.report(show_missing=False)
|
||||
sys.exit(err)
|
||||
|
||||
sys.exit(int(bool(len(result.failures) > 0 or
|
||||
len(result.errors) > 0)))
|
||||
|
||||
|
||||
class TestCommand(TestBaseCommand):
|
||||
|
Loading…
Reference in New Issue
Block a user