tests: Move checkprops.py magic skipping to pytest
We want to skip these tests if previous tests failed or were skipped, but current impl depends on unittest specifics. Move it to pytest Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
61a947d667
commit
f6c6f033d9
|
@ -5,6 +5,9 @@ import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
import tests
|
||||||
|
from tests.utils import TESTCONFIG
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addoption("--uitests", action="store_true", default=False,
|
parser.addoption("--uitests", action="store_true", default=False,
|
||||||
|
@ -70,18 +73,29 @@ def pytest_collection_modifyitems(config, items):
|
||||||
if not find_items("test_urls.py"):
|
if not find_items("test_urls.py"):
|
||||||
# Don't setup urlfetcher mocking for test_urls.py
|
# Don't setup urlfetcher mocking for test_urls.py
|
||||||
# All other tests need it
|
# All other tests need it
|
||||||
import tests.urlfetcher_mock
|
from tests import urlfetcher_mock
|
||||||
tests.urlfetcher_mock.setup_mock()
|
urlfetcher_mock.setup_mock()
|
||||||
|
|
||||||
if find_items("test_inject.py"):
|
if find_items("test_inject.py"):
|
||||||
if not config.getoption("--capture") == "no":
|
if not config.getoption("--capture") == "no":
|
||||||
pytest.fail("test_inject.py requires `pytest --capture=no`")
|
pytest.fail("test_inject.py requires `pytest --capture=no`")
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||||
import tests
|
def pytest_runtest_makereport(item, call):
|
||||||
from tests.utils import TESTCONFIG
|
"""
|
||||||
|
Hooks into test reporting so we can track if any tests didn't
|
||||||
|
pass, so we can skip checkprops checks which require everything to pass.
|
||||||
|
"""
|
||||||
|
ignore = item
|
||||||
|
ignore = call
|
||||||
|
outcome = yield
|
||||||
|
testreport = outcome.get_result()
|
||||||
|
if not testreport.passed:
|
||||||
|
TESTCONFIG.skip_checkprops = True
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_configure(config):
|
||||||
TESTCONFIG.url_iso_only = config.getoption("--urls-iso-only")
|
TESTCONFIG.url_iso_only = config.getoption("--urls-iso-only")
|
||||||
TESTCONFIG.url_only = config.getoption("--urls-url-only")
|
TESTCONFIG.url_only = config.getoption("--urls-url-only")
|
||||||
TESTCONFIG.url_skip_libosinfo = config.getoption("--urls-skip-libosinfo")
|
TESTCONFIG.url_skip_libosinfo = config.getoption("--urls-skip-libosinfo")
|
||||||
|
|
|
@ -2,78 +2,61 @@
|
||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
import unittest
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import tests.utils
|
||||||
|
|
||||||
import virtinst
|
import virtinst
|
||||||
from virtinst import log
|
|
||||||
|
|
||||||
|
|
||||||
_do_skip = None
|
def _skipIfTestsFailed():
|
||||||
|
if tests.utils.TESTCONFIG.skip_checkprops:
|
||||||
|
pytest.skip("Other tests failed or were skipped, don't do prop checks")
|
||||||
|
|
||||||
|
|
||||||
class CheckPropsTest(unittest.TestCase):
|
def testCheckXMLBuilderProps():
|
||||||
maxDiff = None
|
"""
|
||||||
|
If a certain environment variable is set, XMLBuilder tracks
|
||||||
|
every property registered and every one of those that is
|
||||||
|
actually altered. The test suite sets that env variable.
|
||||||
|
If no tests failed or were skipped, we check to ensure the
|
||||||
|
test suite is tickling every XML property
|
||||||
|
"""
|
||||||
|
_skipIfTestsFailed()
|
||||||
|
|
||||||
def _skipIfTestsFailed(self):
|
# pylint: disable=protected-access
|
||||||
# pylint: disable=protected-access
|
fail = [p for p in virtinst.xmlbuilder._allprops
|
||||||
# Access to protected member, needed to unittest stuff
|
if p not in virtinst.xmlbuilder._seenprops]
|
||||||
global _do_skip
|
msg = None
|
||||||
if _do_skip is None:
|
try:
|
||||||
_do_skip = False
|
assert fail == []
|
||||||
try:
|
except AssertionError:
|
||||||
# Accessing an internal detail of unittest, but it's only
|
msg = "".join(traceback.format_exc()) + "\n\n"
|
||||||
# to prevent incorrect output in the case that other tests
|
msg += ("This means that there are XML properties that are\n"
|
||||||
# failed or were skipped, which can give a false positive here
|
"untested in the test suite. This could be caused\n"
|
||||||
result = self._outcome.result
|
"by a previous test suite failure, or if you added\n"
|
||||||
_do_skip = bool(
|
"a new property and didn't extend the test suite.\n"
|
||||||
result.errors or result.failures or result.skipped)
|
"Look into extending test_cli.py and/or test_xmlparse.py.")
|
||||||
except Exception:
|
|
||||||
log.debug("unittest skip hack failed", exc_info=True)
|
|
||||||
|
|
||||||
if _do_skip:
|
if msg:
|
||||||
self.skipTest("skipping as other tests failed/skipped")
|
pytest.fail(msg)
|
||||||
|
|
||||||
def testCheckXMLBuilderProps(self):
|
|
||||||
"""
|
|
||||||
If a certain environment variable is set, XMLBuilder tracks
|
|
||||||
every property registered and every one of those that is
|
|
||||||
actually altered. The test suite sets that env variable.
|
|
||||||
If no tests failed or were skipped, we check to ensure the
|
|
||||||
test suite is tickling every XML property
|
|
||||||
"""
|
|
||||||
self._skipIfTestsFailed()
|
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
def testCheckCLISuboptions():
|
||||||
fail = [p for p in virtinst.xmlbuilder._allprops
|
"""
|
||||||
if p not in virtinst.xmlbuilder._seenprops]
|
Track which command line suboptions and aliases we actually hit with
|
||||||
msg = None
|
the test suite.
|
||||||
try:
|
"""
|
||||||
self.assertEqual([], fail)
|
_skipIfTestsFailed()
|
||||||
except AssertionError:
|
|
||||||
msg = "".join(traceback.format_exc()) + "\n\n"
|
|
||||||
msg += ("This means that there are XML properties that are\n"
|
|
||||||
"untested in the test suite. This could be caused\n"
|
|
||||||
"by a previous test suite failure, or if you added\n"
|
|
||||||
"a new property and didn't extend the test suite.\n"
|
|
||||||
"Look into extending test_cli.py and/or test_xmlparse.py.")
|
|
||||||
|
|
||||||
if msg:
|
# pylint: disable=protected-access
|
||||||
self.fail(msg)
|
from virtinst import cli
|
||||||
|
unchecked = cli._SuboptChecker.get_unseen()
|
||||||
def testCheckCLISuboptions(self):
|
if unchecked:
|
||||||
"""
|
msg = "\n\n"
|
||||||
Track which command line suboptions and aliases we actually hit with
|
msg += "\n".join(sorted(a for a in unchecked)) + "\n\n"
|
||||||
the test suite.
|
msg += ("These command line arguments or aliases are not checked\n"
|
||||||
"""
|
"in the test suite. Please test them.\n"
|
||||||
self._skipIfTestsFailed()
|
"Total unchecked arguments: %s" % len(unchecked))
|
||||||
|
pytest.fail(msg)
|
||||||
# pylint: disable=protected-access
|
|
||||||
from virtinst import cli
|
|
||||||
unchecked = cli._SuboptChecker.get_unseen()
|
|
||||||
if unchecked:
|
|
||||||
msg = "\n\n"
|
|
||||||
msg += "\n".join(sorted(a for a in unchecked)) + "\n\n"
|
|
||||||
msg += ("These command line arguments or aliases are not checked\n"
|
|
||||||
"in the test suite. Please test them.\n"
|
|
||||||
"Total unchecked arguments: %s" % len(unchecked))
|
|
||||||
self.fail(msg)
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ class _TestConfig(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.regenerate_output = False
|
self.regenerate_output = False
|
||||||
self.debug = False
|
self.debug = False
|
||||||
|
self.skip_checkprops = False
|
||||||
|
|
||||||
self.url_only = False
|
self.url_only = False
|
||||||
self.url_iso_only = False
|
self.url_iso_only = False
|
||||||
|
|
Loading…
Reference in New Issue