From b98f9b46de40e7b486cad32e5562595522d5e1ea Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 11 Dec 2017 07:48:13 +0100 Subject: [PATCH] Add marker needs_ipaapi and option to skip tests The new marker needs_ipaapi is used to mark tests that needs an initialized API (ipalib.api) or some sort of other API services (running LDAP server) to work. Some packages use api.Command or api.Backend on module level. They are not marked but rather skipped entirely. A new option ``skip-ipaapi`` is added to skip all API based tests. With the option, only simple unit tests are executed. As of now, freeIPA contains more than 500 unit tests that can be executed in about 5 seconds. Signed-off-by: Christian Heimes Reviewed-By: Alexander Bokovoy --- ipatests/conftest.py | 10 ++++++++++ ipatests/test_cmdline/test_cli.py | 2 ++ ipatests/test_cmdline/test_help.py | 3 +++ ipatests/test_cmdline/test_ipagetkeytab.py | 1 + ipatests/test_install/test_updates.py | 1 + ipatests/test_integration/__init__.py | 1 + ipatests/test_ipalib/test_rpc.py | 2 ++ ipatests/test_ipapython/test_session_storage.py | 1 + ipatests/test_ipaserver/test_ldap.py | 2 ++ ipatests/test_ipaserver/test_serverroles.py | 2 ++ ipatests/test_webui/__init__.py | 1 + ipatests/test_webui/ui_driver.py | 1 + ipatests/test_xmlrpc/__init__.py | 1 + ipatests/util.py | 12 ++++++++++++ 14 files changed, 40 insertions(+) diff --git a/ipatests/conftest.py b/ipatests/conftest.py index c6c846e79..6cc89838b 100644 --- a/ipatests/conftest.py +++ b/ipatests/conftest.py @@ -41,6 +41,7 @@ MARKERS = [ 'cs_acceptance: Acceptance test suite for Dogtag Certificate Server', 'ds_acceptance: Acceptance test suite for 389 Directory Server', 'skip_ipaclient_unittest: Skip in ipaclient unittest mode', + 'needs_ipaapi: Test needs IPA API', ] @@ -95,6 +96,11 @@ def pytest_addoption(parser): help='Run ipaclient unit tests only (no RPC and ipaserver)', action='store_true' ) + group.addoption( + '--skip-ipaapi', + help='Do not run tests that depends on IPA API', + action='store_true', + ) def pytest_cmdline_main(config): @@ -124,3 +130,7 @@ def pytest_runtest_setup(item): # pylint: disable=no-member if pytest.config.option.ipaclient_unittests: pytest.skip("Skip in ipaclient unittest mode") + if item.get_marker('needs_ipaapi'): + # pylint: disable=no-member + if pytest.config.option.skip_ipaapi: + pytest.skip("Skip tests that needs an IPA API") diff --git a/ipatests/test_cmdline/test_cli.py b/ipatests/test_cmdline/test_cli.py index eec0be739..999b84dd3 100644 --- a/ipatests/test_cmdline/test_cli.py +++ b/ipatests/test_cmdline/test_cli.py @@ -20,7 +20,9 @@ TEST_ZONE = u'zoneadd.%(domain)s' % api.env HERE = os.path.abspath(os.path.dirname(__file__)) BASE_DIR = os.path.abspath(os.path.join(HERE, os.pardir, os.pardir)) + @pytest.mark.tier0 +@pytest.mark.needs_ipaapi class TestCLIParsing(object): """Tests that commandlines are correctly parsed to Command keyword args """ diff --git a/ipatests/test_cmdline/test_help.py b/ipatests/test_cmdline/test_help.py index b28aa2303..2656a8df4 100644 --- a/ipatests/test_cmdline/test_help.py +++ b/ipatests/test_cmdline/test_help.py @@ -30,6 +30,9 @@ if six.PY3: unicode = str +pytestmark = pytest.mark.needs_ipaapi + + @pytest.mark.tier0 class CLITestContext(object): """Context manager that replaces stdout & stderr, and catches SystemExit diff --git a/ipatests/test_cmdline/test_ipagetkeytab.py b/ipatests/test_cmdline/test_ipagetkeytab.py index 2f74ae92d..f04f0b930 100644 --- a/ipatests/test_cmdline/test_ipagetkeytab.py +++ b/ipatests/test_cmdline/test_ipagetkeytab.py @@ -67,6 +67,7 @@ def test_service(request, test_host): return service_tracker.make_fixture(request) +@pytest.mark.needs_ipaapi class KeytabRetrievalTest(cmdline_test): """ Base class for keytab retrieval tests diff --git a/ipatests/test_install/test_updates.py b/ipatests/test_install/test_updates.py index 2b1705ffd..6e904f3b1 100644 --- a/ipatests/test_install/test_updates.py +++ b/ipatests/test_install/test_updates.py @@ -48,6 +48,7 @@ The DM password needs to be set in ~/.ipa/.dmpw @pytest.mark.tier0 +@pytest.mark.needs_ipaapi class test_update(unittest.TestCase): """ Test the LDAP updater. diff --git a/ipatests/test_integration/__init__.py b/ipatests/test_integration/__init__.py index 2b4d5350f..045a1e8fd 100644 --- a/ipatests/test_integration/__init__.py +++ b/ipatests/test_integration/__init__.py @@ -20,3 +20,4 @@ import ipatests.util ipatests.util.check_ipaclient_unittests() +ipatests.util.check_no_ipaapi() diff --git a/ipatests/test_ipalib/test_rpc.py b/ipatests/test_ipalib/test_rpc.py index f9ce0b837..20afa8b12 100644 --- a/ipatests/test_ipalib/test_rpc.py +++ b/ipatests/test_ipalib/test_rpc.py @@ -260,6 +260,7 @@ class test_xmlclient(PluginTester): @pytest.mark.skip_ipaclient_unittest +@pytest.mark.needs_ipaapi class test_xml_introspection(object): @classmethod def setup_class(cls): @@ -346,6 +347,7 @@ class test_xml_introspection(object): @pytest.mark.skip_ipaclient_unittest +@pytest.mark.needs_ipaapi class test_rpcclient_context(PluginTester): """ Test the context in `ipalib.rpc.rpcclient` plugin. diff --git a/ipatests/test_ipapython/test_session_storage.py b/ipatests/test_ipapython/test_session_storage.py index 4f9091db3..dde0fe927 100644 --- a/ipatests/test_ipapython/test_session_storage.py +++ b/ipatests/test_ipapython/test_session_storage.py @@ -11,6 +11,7 @@ from ipapython import session_storage @pytest.mark.skip_ipaclient_unittest +@pytest.mark.needs_ipaapi class test_session_storage(object): """ Test the session storage interface diff --git a/ipatests/test_ipaserver/test_ldap.py b/ipatests/test_ipaserver/test_ldap.py index bcf497deb..fb4927f89 100644 --- a/ipatests/test_ipaserver/test_ldap.py +++ b/ipatests/test_ipaserver/test_ldap.py @@ -43,6 +43,7 @@ if six.PY3: @pytest.mark.tier0 +@pytest.mark.needs_ipaapi class test_ldap(object): """ Test various LDAP client bind methods. @@ -135,6 +136,7 @@ class test_ldap(object): @pytest.mark.tier0 +@pytest.mark.needs_ipaapi class test_LDAPEntry(object): """ Test the LDAPEntry class diff --git a/ipatests/test_ipaserver/test_serverroles.py b/ipatests/test_ipaserver/test_serverroles.py index e8967517d..a770c5ff4 100644 --- a/ipatests/test_ipaserver/test_serverroles.py +++ b/ipatests/test_ipaserver/test_serverroles.py @@ -15,6 +15,8 @@ from ipaplatform.paths import paths from ipalib import api, create_api, errors from ipapython.dn import DN +pytestmark = pytest.mark.needs_ipaapi + def _make_service_entry(ldap_backend, dn, enabled=True, other_config=None): mods = { diff --git a/ipatests/test_webui/__init__.py b/ipatests/test_webui/__init__.py index 3f1b63aa8..003034a2a 100644 --- a/ipatests/test_webui/__init__.py +++ b/ipatests/test_webui/__init__.py @@ -24,3 +24,4 @@ import ipatests.util ipatests.util.check_ipaclient_unittests() +ipatests.util.check_no_ipaapi() # also ignore in make fasttest diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py index 23d8127a9..2cd2ba86a 100644 --- a/ipatests/test_webui/ui_driver.py +++ b/ipatests/test_webui/ui_driver.py @@ -59,6 +59,7 @@ except ImportError: NO_YAML = True from ipaplatform.paths import paths + ENV_MAP = { 'MASTER': 'ipa_server', 'ADMINID': 'ipa_admin', diff --git a/ipatests/test_xmlrpc/__init__.py b/ipatests/test_xmlrpc/__init__.py index 0ee42fb4f..ae47d9893 100644 --- a/ipatests/test_xmlrpc/__init__.py +++ b/ipatests/test_xmlrpc/__init__.py @@ -24,3 +24,4 @@ import ipatests.util ipatests.util.check_ipaclient_unittests() +ipatests.util.check_no_ipaapi() # also ignore in make fasttest diff --git a/ipatests/util.py b/ipatests/util.py index 98369ed8d..1dc2a81e3 100644 --- a/ipatests/util.py +++ b/ipatests/util.py @@ -78,6 +78,18 @@ def check_ipaclient_unittests(reason="Skip in ipaclient unittest mode"): raise pytest.skip(reason) +def check_no_ipaapi(reason="Skip tests that needs an IPA API"): + """Call this in a package to skip the package in no-ipaapi mode + """ + if pytest.config.getoption('skip_ipaapi', False): + if PYTEST_VERSION[0] >= 3: + # pylint: disable=unexpected-keyword-arg + raise pytest.skip.Exception(reason, allow_module_level=True) + # pylint: enable=unexpected-keyword-arg + else: + raise pytest.skip(reason) + + class TempDir(object): def __init__(self): self.__path = tempfile.mkdtemp(prefix='ipa.tests.')