Module: check_mk
Branch: master
Commit: f52a8a4d75fd34a9a70a10ffa4c25b5b71807228
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f52a8a4d75fd34…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Dec 5 08:09:59 2018 +0100
YAPFed file
Change-Id: Iade3510e5788092cbcb4d473a2e73e994134e2b2
---
tests/conftest.py | 60 +++++++++++++++++++++++++++++++++----------------------
1 file changed, 36 insertions(+), 24 deletions(-)
diff --git a/tests/conftest.py b/tests/conftest.py
index 7d37c03..9a338c5 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -33,31 +33,35 @@ import testlib
EXECUTE_IN_SITE, EXECUTE_IN_VENV = True, False
test_types = collections.OrderedDict([
- ("unit", EXECUTE_IN_VENV),
- ("pylint", EXECUTE_IN_VENV),
- ("docker", EXECUTE_IN_VENV),
+ ("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),
+ ("gui_crawl", EXECUTE_IN_SITE),
+ ("packaging", EXECUTE_IN_VENV),
])
+
def pytest_addoption(parser):
"""Register the -T option to pytest"""
- options = [ name for opt in parser._anonymous.options for name in opt.names() ]
+ 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()))
+ parser.addoption(
+ "-T",
+ action="store",
+ metavar="TYPE",
+ default=None,
+ help="Run tests of the given TYPE. Available types are: %s" % ",
".join(test_types.keys()))
+
def pytest_configure(config):
"""Register the type marker to pytest"""
- config.addinivalue_line("markers",
- "type(TYPE): Mark TYPE of test. Available: %s" %
- ", ".join(test_types.keys()))
+ config.addinivalue_line(
+ "markers", "type(TYPE): Mark TYPE of test. Available: %s" %
", ".join(test_types.keys()))
def pytest_collection_modifyitems(items):
@@ -65,7 +69,7 @@ def pytest_collection_modifyitems(items):
for item in items:
type_marker = item.get_closest_marker("type")
if type_marker and type_marker.args:
- continue # Do not modify manually set marks
+ continue # Do not modify manually set marks
file_path = "%s" % item.reportinfo()[0]
if "tests/unit" in file_path:
@@ -105,13 +109,15 @@ def fake_version_and_paths():
import cmk
monkeypatch.setattr(cmk, "omd_version", lambda: "%s.cee" %
cmk.__version__)
- monkeypatch.setattr("cmk.paths.checks_dir", "%s/checks" %
cmk_path())
- monkeypatch.setattr("cmk.paths.notifications_dir",
"%s/notifications" % cmk_path())
- monkeypatch.setattr("cmk.paths.inventory_dir",
"%s/inventory" % cmk_path())
+ monkeypatch.setattr("cmk.paths.checks_dir", "%s/checks" %
cmk_path())
+ monkeypatch.setattr("cmk.paths.notifications_dir",
"%s/notifications" % cmk_path())
+ monkeypatch.setattr("cmk.paths.inventory_dir", "%s/inventory" %
cmk_path())
monkeypatch.setattr("cmk.paths.check_manpages_dir", "%s/checkman"
% cmk_path())
- monkeypatch.setattr("cmk.paths.tmp_dir", tmp_dir)
- monkeypatch.setattr("cmk.paths.precompiled_checks_dir",
os.path.join(tmp_dir, "var/check_mk/precompiled_checks"))
- monkeypatch.setattr("cmk.paths.include_cache_dir",
os.path.join(tmp_dir, "check_mk/check_includes"))
+ monkeypatch.setattr("cmk.paths.tmp_dir", tmp_dir)
+ monkeypatch.setattr("cmk.paths.precompiled_checks_dir",
+ os.path.join(tmp_dir,
"var/check_mk/precompiled_checks"))
+ monkeypatch.setattr("cmk.paths.include_cache_dir",
+ os.path.join(tmp_dir, "check_mk/check_includes"))
# Cleanup temporary directory created above
@@ -167,7 +173,7 @@ def pytest_cmdline_main(config):
Depending on the selected "type" marker the environment is ensured
or switched here."""
if not config.getoption("-T"):
- return # missing option is handled later
+ return # missing option is handled later
context = test_types[config.getoption("-T")]
if context == EXECUTE_IN_SITE:
@@ -179,15 +185,16 @@ def pytest_cmdline_main(config):
def verify_virtualenv():
if not testlib.virtualenv_path():
raise SystemExit("ERROR: Please load virtual environment first "
- "(Use \"pipenv shell\" or configure
direnv)")
+ "(Use \"pipenv shell\" or configure
direnv)")
def is_running_as_site_user():
return pwd.getpwuid(os.getuid()).pw_name == _site_id()
+
def setup_site_and_switch_user():
if is_running_as_site_user():
- return # This is executed as site user. Nothing to be done.
+ return # This is executed as site user. Nothing to be done.
sys.stdout.write("===============================================\n")
sys.stdout.write("Setting up site '%s'\n" % _site_id())
@@ -233,8 +240,12 @@ def _get_site_object():
def reuse_site():
return os.environ.get("REUSE", "1") == "1"
- return testlib.Site(site_id=_site_id(), version=site_version(),
- edition=site_edition(), reuse=reuse_site(),
branch=site_branch())
+ return testlib.Site(
+ site_id=_site_id(),
+ version=site_version(),
+ edition=site_edition(),
+ reuse=reuse_site(),
+ branch=site_branch())
def _site_id():
@@ -253,6 +264,7 @@ def _site_id():
add_python_paths()
fake_version_and_paths()
+
# Session fixtures must be in conftest.py to work properly
@pytest.fixture(scope="session", autouse=True)
def site(request):