URL: https://github.com/freeipa/freeipa/pull/475
Author: tiran
 Title: #475: Add options to run only ipaclient unittests
Action: opened

PR body:
"""
A new option for ipa-run-tests makes the test runner ignore
subdirectories or skips tests that depend on the ipaserver package or on
a running framework for RPC integration tests. The new option enables
testing of client-only builds.

$ ipatests/ipa-run-tests --ipaclient-unittests
...
platform linux2 -- Python 2.7.13, pytest-2.9.2, py-1.4.32, pluggy-0.3.1
rootdir: /home/heimes/redhat, inifile: tox.ini
plugins: sourceorder-0.5, cov-2.3.0, betamax-0.7.1, multihost-1.1
collected 451 items

test_util.py ........
util.py ..
test_ipaclient/test_csrgen.py ..............ssss...
test_ipalib/test_aci.py ...................
test_ipalib/test_backend.py ........
test_ipalib/test_base.py ...............
test_ipalib/test_capabilities.py .
test_ipalib/test_cli.py ...
test_ipalib/test_config.py ...............
test_ipalib/test_crud.py ...............
test_ipalib/test_errors.py .......
test_ipalib/test_frontend.py ........................................
test_ipalib/test_messages.py ....
test_ipalib/test_output.py ...
test_ipalib/test_parameters.py 
.............................................................
test_ipalib/test_plugable.py ........
test_ipalib/test_rpc.py ......ssssssss
test_ipalib/test_text.py .............................
test_ipalib/test_x509.py ...
test_ipapython/test_cookie.py ............
test_ipapython/test_dn.py ...........................
test_ipapython/test_ipautil.py 
..................................................................
test_ipapython/test_ipavalidate.py ..........
test_ipapython/test_kerberos.py ..............
test_ipapython/test_keyring.py ..........
test_ipapython/test_ssh.py ...............................
test_pkcs10/test_pkcs10.py .....

https://fedorahosted.org/freeipa/ticket/6517

Signed-off-by: Christian Heimes <chei...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/475/head:pr475
git checkout pr475
From 95bffaca57427368e4c0ef1e608ffc17f27524d9 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Fri, 17 Feb 2017 08:39:54 +0100
Subject: [PATCH] Add options to run only ipaclient unittests

A new option for ipa-run-tests makes the test runner ignore
subdirectories or skips tests that depend on the ipaserver package or on
a running framework for RPC integration tests. The new option enables
testing of client-only builds.

$ ipatests/ipa-run-tests --ipaclient-unittests
...
platform linux2 -- Python 2.7.13, pytest-2.9.2, py-1.4.32, pluggy-0.3.1
rootdir: /home/heimes/redhat, inifile: tox.ini
plugins: sourceorder-0.5, cov-2.3.0, betamax-0.7.1, multihost-1.1
collected 451 items

test_util.py ........
util.py ..
test_ipaclient/test_csrgen.py ..............ssss...
test_ipalib/test_aci.py ...................
test_ipalib/test_backend.py ........
test_ipalib/test_base.py ...............
test_ipalib/test_capabilities.py .
test_ipalib/test_cli.py ...
test_ipalib/test_config.py ...............
test_ipalib/test_crud.py ...............
test_ipalib/test_errors.py .......
test_ipalib/test_frontend.py ........................................
test_ipalib/test_messages.py ....
test_ipalib/test_output.py ...
test_ipalib/test_parameters.py .............................................................
test_ipalib/test_plugable.py ........
test_ipalib/test_rpc.py ......ssssssss
test_ipalib/test_text.py .............................
test_ipalib/test_x509.py ...
test_ipapython/test_cookie.py ............
test_ipapython/test_dn.py ...........................
test_ipapython/test_ipautil.py ..................................................................
test_ipapython/test_ipavalidate.py ..........
test_ipapython/test_kerberos.py ..............
test_ipapython/test_keyring.py ..........
test_ipapython/test_ssh.py ...............................
test_pkcs10/test_pkcs10.py .....

https://fedorahosted.org/freeipa/ticket/6517

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipatests/conftest.py                   | 62 +++++++++++++++++++++++++++++++++-
 ipatests/setup.py                      |  1 -
 ipatests/test_ipaclient/test_csrgen.py |  1 +
 ipatests/test_ipalib/test_rpc.py       |  2 ++
 ipatests/util.py                       | 15 ++++++--
 5 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/ipatests/conftest.py b/ipatests/conftest.py
index 511d7b7..32f24cf 100644
--- a/ipatests/conftest.py
+++ b/ipatests/conftest.py
@@ -3,17 +3,26 @@
 #
 from __future__ import print_function
 
+import fnmatch
 import os
 import pprint
+import re
 import sys
 
+import pytest
+
 from ipalib import api
 from ipalib.cli import cli_plugins
 try:
+    import ipaplatform
+except ImportError:
+    ipaplatform = None
+try:
     import ipaserver
 except ImportError:
     ipaserver = None
 
+HERE = os.path.dirname(os.path.abspath(__file__))
 
 pytest_plugins = [
     'ipatests.pytest_plugins.additional_config',
@@ -31,6 +40,7 @@
     'tier1: functional API tests',
     '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',
 ]
 
 
@@ -46,6 +56,28 @@
     'install/share'
 ]
 
+
+SKIP_IPASERVER_PATTERNS = [
+    # fnmatch patterns
+    'test_cmdline/*',
+    'test_install/*',
+    'test_integration/*',
+    'test_ipaserver/*',
+    'test_webui/*',
+    'test_xmlrpc/*'
+]
+
+if ipaplatform is None:
+    # test depends on ipaplatform
+    SKIP_IPASERVER_PATTERNS.append('test_ipaclient/test_csrgen.py')
+
+SKIP_IPASERVER_RE = re.compile(
+    '(' +
+    '|'.join(fnmatch.translate(pat) for pat in SKIP_IPASERVER_PATTERNS) +
+    ')'
+)
+
+
 INIVALUES = {
     'python_classes': ['test_', 'Test'],
     'python_files': ['test_*.py'],
@@ -75,13 +107,27 @@ def pytest_configure(config):
     config.option.doctestmodules = True
 
 
+def pytest_addoption(parser):
+    group = parser.getgroup("IPA integration tests")
+    group.addoption(
+        '--ipaclient-unittests',
+        help='Run ipaclient unit tests only (no RPC and ipaserver)',
+        action='store_true'
+    )
+
+
 def pytest_cmdline_main(config):
     api.bootstrap(
         context=u'cli', in_server=False, in_tree=True, fallback=False
     )
     for klass in cli_plugins:
         api.add_plugin(klass)
-    api.finalize()
+
+    # XXX workaround until https://fedorahosted.org/freeipa/ticket/6408 has
+    # been resolved.
+    if ipaserver is not None:
+        api.finalize()
+
     if config.option.verbose:
         print('api.env: ')
         pprint.pprint({k: api.env[k] for k in api.env})
@@ -89,3 +135,17 @@ def pytest_cmdline_main(config):
         print("euid: {}, egid: {}".format(os.geteuid(), os.getegid()))
         print("working dir: {}".format(os.path.abspath(os.getcwd())))
         print('sys.version: {}'.format(sys.version))
+
+
+def pytest_ignore_collect(path, config):
+    if config.option.ipaclient_unittests:
+        relative = path.relto(HERE)
+        if SKIP_IPASERVER_RE.match(relative):
+            return True
+
+
+def pytest_runtest_setup(item):
+    if isinstance(item, item.Function):
+        if item.get_marker('skip_ipaclient_unittest'):
+            if pytest.config.option.ipaclient_unittests:
+                pytest.skip("Skip in ipaclient unittest mode")
diff --git a/ipatests/setup.py b/ipatests/setup.py
index e46e922..56d549a 100644
--- a/ipatests/setup.py
+++ b/ipatests/setup.py
@@ -64,7 +64,6 @@
             "gssapi",
             "ipaclient",
             "ipalib",
-            "ipaplatform",
             "ipapython",
             "nose",
             "polib",
diff --git a/ipatests/test_ipaclient/test_csrgen.py b/ipatests/test_ipaclient/test_csrgen.py
index 556f8e0..24467f0 100644
--- a/ipatests/test_ipaclient/test_csrgen.py
+++ b/ipatests/test_ipaclient/test_csrgen.py
@@ -185,6 +185,7 @@ def test_rules_for_profile_nosuchprofile(self, rule_provider):
             rule_provider.rules_for_profile('nosuchprofile', 'certutil')
 
 
+@pytest.mark.skip_ipaclient_unittest
 class test_CSRGenerator(object):
     def test_userCert_OpenSSL(self, generator):
         principal = {
diff --git a/ipatests/test_ipalib/test_rpc.py b/ipatests/test_ipalib/test_rpc.py
index 80cf2e7..7fe0580 100644
--- a/ipatests/test_ipalib/test_rpc.py
+++ b/ipatests/test_ipalib/test_rpc.py
@@ -23,6 +23,7 @@
 from __future__ import print_function
 
 import nose
+import pytest
 import six
 # pylint: disable=import-error
 from six.moves.xmlrpc_client import Binary, Fault, dumps, loads
@@ -256,6 +257,7 @@ class user_add(Command):
         assert context.xmlclient.conn._calledall() is True
 
 
+@pytest.mark.skip_ipaclient_unittest
 class test_xml_introspection(object):
     @classmethod
     def setup_class(cls):
diff --git a/ipatests/util.py b/ipatests/util.py
index f55ef73..3c5c3af 100644
--- a/ipatests/util.py
+++ b/ipatests/util.py
@@ -39,12 +39,23 @@
 
 import ipalib
 from ipalib import api
-from ipalib.install.kinit import kinit_keytab, kinit_password
 from ipalib.plugable import Plugin
 from ipalib.request import context
 from ipapython.dn import DN
 from ipapython.ipautil import run
-from ipaplatform.paths import paths
+
+try:
+    # not available with client-only wheel packages
+    from ipalib.install.kinit import kinit_keytab, kinit_password
+except ImportError:
+    kinit_keytab = kinit_password = None
+
+try:
+    # not available with client-only wheel packages
+    from ipaplatform.paths import paths
+except ImportError:
+    paths = None
+
 
 if six.PY3:
     unicode = str
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to