Module: check_mk
Branch: master
Commit: edde1d705aa6a6cc9badbd62975c8b0becd2ddc6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=edde1d705aa6a6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Nov 12 12:21:53 2018 +0100
Another approach to fix test selection after py.test 3.10.0 update
Change-Id: Ie014391ee21969b8682ea80ca552c592eb38fde6
---
conftest.py | 19 +++++++++++++++++++
tests/conftest.py | 17 +++++++----------
tests/testlib/__init__.py | 14 ++++++++++++++
3 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/conftest.py b/conftest.py
new file mode 100644
index 0000000..027d5ac
--- /dev/null
+++ b/conftest.py
@@ -0,0 +1,19 @@
+import collections
+
+EXECUTE_IN_SITE, EXECUTE_IN_VENV = True, False
+
+test_types = collections.OrderedDict([
+ ("unit", EXECUTE_IN_VENV),
+ ("pylint", EXECUTE_IN_VENV),
+ ("docker", EXECUTE_IN_VENV),
+ ("integration", EXECUTE_IN_SITE),
+ ("gui_crawl", EXECUTE_IN_SITE),
+ ("packaging", EXECUTE_IN_VENV),
+])
+
+
+def pytest_addoption(parser):
+ """Register the -T option to pytest"""
+ parser.addoption("-T", action="store", metavar="TYPE",
default=None,
+ help="Run tests of the given TYPE. Available types are: %s" %
+ ", ".join(test_types.keys()))
diff --git a/tests/conftest.py b/tests/conftest.py
index d24a751..ff075ac 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -43,6 +43,12 @@ test_types = collections.OrderedDict([
def pytest_addoption(parser):
"""Register the -T option to pytest"""
+ options = [ name for opt in parser._anonymous.options for name in opt.names() ]
+ # conftest.py is symlinked from enterprise/tests/conftest.py which makes it being
executed
+ # twice. Only register this option once.
+ if "-T" in options:
+ return
+
parser.addoption("-T", action="store", metavar="TYPE",
default=None,
help="Run tests of the given TYPE. Available types are: %s" %
", ".join(test_types.keys()))
@@ -82,16 +88,7 @@ def pytest_collection_modifyitems(items):
def pytest_runtest_setup(item):
"""Skip tests of unwanted types"""
- test_type = item.get_closest_marker("type")
- if test_type is None:
- raise Exception("Test is not TYPE marked: %s" % item)
-
- if not item.config.getoption("-T"):
- raise SystemExit("Please specify type of tests to be executed (py.test -T
TYPE)")
-
- test_type_name = test_type.args[0]
- if test_type_name != item.config.getoption("-T"):
- pytest.skip("Not testing type %r" % test_type_name)
+ testlib.skip_unwanted_test_types(item)
# Some cmk.* code is calling things like cmk. is_raw_edition() at import time
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 2e33ff1..2f24a39 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -27,6 +27,20 @@ from bs4 import BeautifulSoup
# Disable insecure requests warning message during SSL testing
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+
+def skip_unwanted_test_types(item):
+ test_type = item.get_closest_marker("type")
+ if test_type is None:
+ raise Exception("Test is not TYPE marked: %s" % item)
+
+ if not item.config.getoption("-T"):
+ raise SystemExit("Please specify type of tests to be executed (py.test -T
TYPE)")
+
+ test_type_name = test_type.args[0]
+ if test_type_name != item.config.getoption("-T"):
+ pytest.skip("Not testing type %r" % test_type_name)
+
+
def repo_path():
return os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))