uitests: Wire up --coverage

Need to launch the external coverage process to actually measure
things
This commit is contained in:
Cole Robinson 2018-01-08 18:00:14 -05:00
parent b4a2c46f6a
commit 4b4f532417
4 changed files with 19 additions and 13 deletions

View File

@ -390,6 +390,7 @@ class TestBaseCommand(distutils.core.Command):
self._dir = os.getcwd()
self.testfile = None
self._force_verbose = False
self._external_coverage = False
def finalize_options(self):
if self.debug and "DEBUG_TESTS" not in os.environ:
@ -423,16 +424,16 @@ class TestBaseCommand(distutils.core.Command):
cov = None
if self.coverage:
import coverage
# The latter is required to not give errors on f23, probably
# a temporary bug.
omit = ["/usr/*", "/*/tests/*", "/builddir/*"]
omit = ["/usr/*", "/*/tests/*"]
cov = coverage.coverage(omit=omit)
cov.erase()
cov.start()
if not self._external_coverage:
cov.start()
import tests as testsmodule
testsmodule.utils.clistate.regenerate_output = bool(
self.regenerate_output)
testsmodule.utils.clistate.use_coverage = bool(cov)
# This makes the test runner report results before exiting from ctrl-c
unittest.installHandler()
@ -466,8 +467,11 @@ class TestBaseCommand(distutils.core.Command):
sys.exit(1)
if cov:
cov.stop()
cov.save()
if self._external_coverage:
cov.load()
else:
cov.stop()
cov.save()
err = int(bool(len(result.failures) > 0 or
len(result.errors) > 0))
@ -516,6 +520,7 @@ class TestUI(TestBaseCommand):
def run(self):
self._testfiles = self._find_tests_in_dir("tests/uitests", [])
self._force_verbose = True
self._external_coverage = True
TestBaseCommand.run(self)

View File

@ -16,8 +16,6 @@ class NewVM(uiutils.UITestCase):
###################
def _open_create_wizard(self):
conn_label = "test testdriver.xml"
uiutils.find_pattern(self.app.root, conn_label, "table cell")
b = uiutils.find_pattern(self.app.root, "New", "push button",
wait_for_focus=True)
b.click()

View File

@ -90,12 +90,14 @@ class DogtailApp(object):
stdout = open(os.devnull)
stderr = open(os.devnull)
self._proc = subprocess.Popen([sys.executable,
os.path.join(os.getcwd(), "virt-manager"),
"--test-first-run", "--no-fork", "--connect", self.uri] +
extra_opts,
stdout=stdout, stderr=stderr)
cmd = [sys.executable]
if tests.utils.clistate.use_coverage:
cmd += ["-m", "coverage", "run", "--append"]
cmd += [os.path.join(os.getcwd(), "virt-manager"),
"--test-first-run", "--no-fork", "--connect", self.uri]
cmd += extra_opts
self._proc = subprocess.Popen(cmd, stdout=stdout, stderr=stderr)
self._root = dogtail.tree.root.application("virt-manager")
def stop(self):

View File

@ -32,6 +32,7 @@ class _CLIState(object):
"""
def __init__(self):
self.regenerate_output = False
self.use_coverage = False
clistate = _CLIState()