URL: https://github.com/freeipa/freeipa/pull/619
Author: tiran
 Title: #619: pytest 3.x compatibility
Action: opened

PR body:
"""
pytest 3.x does no longer support plain pytest.skip() on module level.

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/619/head:pr619
git checkout pr619
From 3e2ad3b16f1a12aaba768811143f12b8a042b896 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Fri, 17 Mar 2017 18:20:38 +0100
Subject: [PATCH] pytest 3.x compatibility

pytest 3.x does no longer support plain pytest.skip() on module level.

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipatests/test_cmdline/__init__.py     |  6 ++----
 ipatests/test_install/__init__.py     |  5 ++---
 ipatests/test_integration/__init__.py |  5 ++---
 ipatests/test_ipaserver/__init__.py   |  6 ++----
 ipatests/test_webui/__init__.py       |  5 ++---
 ipatests/test_xmlrpc/__init__.py      |  5 ++---
 ipatests/util.py                      | 14 ++++++++++++++
 7 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/ipatests/test_cmdline/__init__.py b/ipatests/test_cmdline/__init__.py
index af8867e..52eb23e 100644
--- a/ipatests/test_cmdline/__init__.py
+++ b/ipatests/test_cmdline/__init__.py
@@ -1,9 +1,7 @@
 #
 # Copyright (C) 2015  FreeIPA Contributors see COPYING for license
 #
+import ipatests.util
 
-import pytest
 
-
-if pytest.config.getoption('ipaclient_unittests', False):
-    pytest.skip("Skip in ipaclient unittest mode")
+ipatests.util.check_ipaclient_unittests()
diff --git a/ipatests/test_install/__init__.py b/ipatests/test_install/__init__.py
index 54ef9eb..1d5fd0b 100644
--- a/ipatests/test_install/__init__.py
+++ b/ipatests/test_install/__init__.py
@@ -20,8 +20,7 @@
 """
 Package containing LDAP updates unit tests.
 """
-import pytest
+import ipatests.util
 
 
-if pytest.config.getoption('ipaclient_unittests', False):
-    pytest.skip("Skip in ipaclient unittest mode")
+ipatests.util.check_ipaclient_unittests()
diff --git a/ipatests/test_integration/__init__.py b/ipatests/test_integration/__init__.py
index 8779f2f..2b4d535 100644
--- a/ipatests/test_integration/__init__.py
+++ b/ipatests/test_integration/__init__.py
@@ -16,8 +16,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-import pytest
+import ipatests.util
 
 
-if pytest.config.getoption('ipaclient_unittests', False):
-    pytest.skip("Skip in ipaclient unittest mode")
+ipatests.util.check_ipaclient_unittests()
diff --git a/ipatests/test_ipaserver/__init__.py b/ipatests/test_ipaserver/__init__.py
index 76942c7..22d36ea 100644
--- a/ipatests/test_ipaserver/__init__.py
+++ b/ipatests/test_ipaserver/__init__.py
@@ -20,9 +20,7 @@
 """
 Sub-package containing unit tests for `ipaserver` package.
 """
+import ipatests.util
 
-import pytest
 
-
-if pytest.config.getoption('ipaclient_unittests', False):
-    pytest.skip("Skip in ipaclient unittest mode")
+ipatests.util.check_ipaclient_unittests()
diff --git a/ipatests/test_webui/__init__.py b/ipatests/test_webui/__init__.py
index cb2f361..3f1b63a 100644
--- a/ipatests/test_webui/__init__.py
+++ b/ipatests/test_webui/__init__.py
@@ -20,8 +20,7 @@
 """
 Sub-package containing Web UI integration tests
 """
-import pytest
+import ipatests.util
 
 
-if pytest.config.getoption('ipaclient_unittests', False):
-    pytest.skip("Skip in ipaclient unittest mode")
+ipatests.util.check_ipaclient_unittests()
diff --git a/ipatests/test_xmlrpc/__init__.py b/ipatests/test_xmlrpc/__init__.py
index 720c61b..0ee42fb 100644
--- a/ipatests/test_xmlrpc/__init__.py
+++ b/ipatests/test_xmlrpc/__init__.py
@@ -20,8 +20,7 @@
 """
 Sub-package containing unit tests for `xmlrpc` package.
 """
-import pytest
+import ipatests.util
 
 
-if pytest.config.getoption('ipaclient_unittests', False):
-    pytest.skip("Skip in ipaclient unittest mode")
+ipatests.util.check_ipaclient_unittests()
diff --git a/ipatests/util.py b/ipatests/util.py
index 4379c30..92c47c2 100644
--- a/ipatests/util.py
+++ b/ipatests/util.py
@@ -61,6 +61,20 @@
     unicode = str
 
 
+PYTEST_VERSION = tuple(int(v) for v in pytest.__version__.split('.'))
+
+
+def check_ipaclient_unittests(reason="Skip in ipaclient unittest mode"):
+    """Call this in a package to skip the package in ipaclient-unittest mode
+    """
+    if pytest.config.getoption('ipaclient_unittests', False):
+        if PYTEST_VERSION[0] >= 3:
+            # pytest 3+ does no longer allow pytest.skip() on module leve
+            raise pytest.skip.Exception(reason, allow_module_level=True)
+        else:
+            raise pytest.skip(reason)
+
+
 class TempDir(object):
     def __init__(self):
         self.__path = tempfile.mkdtemp(prefix='ipa.tests.')
-- 
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