Module: check_mk
Branch: master
Commit: 68559a03a3d02ff4af131a24e07f538b8fd6931b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=68559a03a3d02f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat Apr 6 12:28:24 2019 +0200
Generalized load_plugins fixture and cleaned up call sites
Change-Id: Ie40c1dd30bc62ef6be08908b269739fb650a1645
---
tests/unit/cmk/gui/conftest.py | 9 +++++++++
tests/unit/cmk/gui/test_gui_config.py | 8 +-------
tests/unit/cmk/gui/test_views.py | 19 +++++++------------
tests/unit/cmk/gui/test_visuals.py | 20 ++++++++------------
4 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/tests/unit/cmk/gui/conftest.py b/tests/unit/cmk/gui/conftest.py
index 6f049a9..636150a 100644
--- a/tests/unit/cmk/gui/conftest.py
+++ b/tests/unit/cmk/gui/conftest.py
@@ -47,3 +47,12 @@ def load_config(register_builtin_html):
yield
cmk.utils.log.logger.setLevel(old_root_log_level)
+
+
+(a)pytest.fixture()
+def load_plugins(register_builtin_html, monkeypatch, tmpdir):
+ import cmk.gui.modules as modules
+ config_dir = Path("%s" % tmpdir) / "var/check_mk/web"
+ config_dir.mkdir(parents=True) # pylint: disable=no-member
+ monkeypatch.setattr(config, "config_dir", "%s" % config_dir)
+ modules.load_all_plugins()
diff --git a/tests/unit/cmk/gui/test_gui_config.py
b/tests/unit/cmk/gui/test_gui_config.py
index 53d6c18..0077f41 100644
--- a/tests/unit/cmk/gui/test_gui_config.py
+++ b/tests/unit/cmk/gui/test_gui_config.py
@@ -16,13 +16,7 @@ from cmk.gui.permissions import (
permission_registry,
)
-
-(a)pytest.fixture(autouse=True)
-def load_plugins(register_builtin_html, monkeypatch, tmpdir):
- config_dir = Path("%s" % tmpdir).joinpath("var/check_mk/web")
- config_dir.mkdir(parents=True) # pylint: disable=no-member
- monkeypatch.setattr(config, "config_dir", "%s" % config_dir)
- modules.load_all_plugins()
+pytestmark = pytest.mark.usefixtures("load_plugins")
def test_registered_permission_sections():
diff --git a/tests/unit/cmk/gui/test_views.py b/tests/unit/cmk/gui/test_views.py
index 51a0290..c5801fc 100644
--- a/tests/unit/cmk/gui/test_views.py
+++ b/tests/unit/cmk/gui/test_views.py
@@ -14,16 +14,8 @@ from cmk.gui.valuespec import ValueSpec
import cmk.gui.plugins.views
import cmk.gui.modules as modules
-
-(a)pytest.fixture()
-def load_view_plugins(register_builtin_html, monkeypatch, tmpdir):
- config_dir = Path("%s" % tmpdir).joinpath("var/check_mk/web")
- config_dir.mkdir(parents=True) # pylint: disable=no-member
- monkeypatch.setattr(config, "config_dir", "%s" % config_dir)
- modules.load_all_plugins()
-
@pytest.fixture()
-def view(register_builtin_html, load_view_plugins):
+def view(register_builtin_html, load_plugins):
view_name = "allhosts"
view_spec = cmk.gui.views.multisite_builtin_views[view_name]
return cmk.gui.views.View(view_name, view_spec)
@@ -701,7 +693,8 @@ def test_registered_datasources():
# These tests make adding new elements needlessly painful.
# Skip pending discussion with development team.
@pytest.mark.skip
-def test_registered_painters(load_view_plugins):
+(a)pytest.mark.usefixture("load_plugins")
+def test_registered_painters():
expected = {
'aggr_acknowledged': {
'columns': ['aggr_effective_state'],
@@ -4084,7 +4077,8 @@ def test_legacy_register_painter(monkeypatch):
# These tests make adding new elements needlessly painful.
# Skip pending discussion with development team.
@pytest.mark.skip
-def test_registered_sorters(load_view_plugins):
+(a)pytest.mark.usefixture("load_plugins")
+def test_registered_sorters():
expected = {
'aggr_group': {
'columns': ['aggr_group'],
@@ -5781,7 +5775,8 @@ def test_get_needed_join_columns(view):
'service_description',
])
-def test_create_view_basics(load_view_plugins):
+(a)pytest.mark.usefixture("load_plugins")
+def test_create_view_basics():
view_name = "allhosts"
view_spec = cmk.gui.views.multisite_builtin_views[view_name]
view = cmk.gui.views.View(view_name, view_spec)
diff --git a/tests/unit/cmk/gui/test_visuals.py b/tests/unit/cmk/gui/test_visuals.py
index d265766..f65c592 100644
--- a/tests/unit/cmk/gui/test_visuals.py
+++ b/tests/unit/cmk/gui/test_visuals.py
@@ -10,14 +10,6 @@ import cmk.gui.visuals as visuals
import cmk.gui.modules as modules
-(a)pytest.fixture()
-def load_plugins(register_builtin_html, monkeypatch, tmpdir):
- config_dir = Path("%s" % tmpdir).joinpath("var/check_mk/web")
- config_dir.mkdir(parents=True) # pylint: disable=no-member
- monkeypatch.setattr(config, "config_dir", "%s" % config_dir)
- modules.load_all_plugins()
-
-
def test_get_filter():
f = visuals.get_filter("hostregex")
assert isinstance(f, cmk.gui.plugins.visuals.Filter)
@@ -71,11 +63,13 @@ expected_visual_types = {
}
-def test_registered_visual_types(load_plugins):
+(a)pytest.mark.usefixture("load_plugins")
+def test_registered_visual_types():
assert sorted(utils.visual_type_registry.keys()) ==
sorted(expected_visual_types.keys())
-def test_registered_visual_type_attributes(load_plugins):
+(a)pytest.mark.usefixture("load_plugins")
+def test_registered_visual_type_attributes():
for ident, plugin_class in utils.visual_type_registry.items():
plugin = plugin_class()
spec = expected_visual_types[ident]
@@ -3658,14 +3652,16 @@ expected_infos = {
# These tests make adding new elements needlessly painful.
# Skip pending discussion with development team.
@pytest.mark.skip
-def test_registered_infos(load_plugins):
+(a)pytest.mark.usefixture("load_plugins")
+def test_registered_infos():
assert sorted(utils.visual_info_registry.keys()) == sorted(expected_infos.keys())
# These tests make adding new elements needlessly painful.
# Skip pending discussion with development team.
@pytest.mark.skip
-def test_registered_info_attributes(load_plugins):
+(a)pytest.mark.usefixture("load_plugins")
+def test_registered_info_attributes():
for ident, cls in utils.visual_info_registry.items():
info = cls()
spec = expected_infos[ident]