Module: check_mk
Branch: master
Commit: 0c132f87d2cb9715495be7d3595cee7261b63339
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0c132f87d2cb97…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Aug 1 14:44:05 2016 +0200
Tests: Correctly using session scope site management
---
tests/conftest.py | 39 +++++++++++++++++++++++++++++++++++
tests/livestatus/test_livestatus.py | 2 +-
tests/omd/test_python.py | 2 --
tests/testlib/__init__.py | 35 +------------------------------
tests/web/test_crawl.py | 2 +-
tests/web/test_login.py | 2 +-
tests/web/test_wato_webapi.py | 2 +-
7 files changed, 44 insertions(+), 40 deletions(-)
diff --git a/tests/conftest.py b/tests/conftest.py
index 0b7af07..bc8865b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,6 +3,8 @@ import os
import sys
import glob
import pytest
+import testlib
+
def cmk_path():
return os.path.dirname(os.path.dirname(__file__))
@@ -67,3 +69,40 @@ def pytest_runtest_setup(item):
add_python_paths()
ensure_equal_branches()
+
+import testlib
+
+# Session fixtures must be in conftest.py to work properly
+(a)pytest.fixture(scope="session")
+def site(request):
+ def site_id():
+ site_id = os.environ.get("SITE")
+ if site_id == None:
+ site_id = file(testlib.repo_path() + "/.site").read().strip()
+
+ return site_id
+
+ def site_version():
+ return os.environ.get("VERSION", testlib.CMKVersion.DEFAULT)
+
+ def site_edition():
+ return os.environ.get("EDITION", testlib.CMKVersion.CEE)
+
+ def reuse_site():
+ return os.environ.get("REUSE", "1") == "1"
+
+ site = testlib.Site(site_id=site_id(), version=site_version(),
+ edition=site_edition(), reuse=reuse_site())
+ site.cleanup_if_wrong_version()
+ site.create()
+ site.open_livestatus_tcp()
+ site.start()
+ site.prepare_for_tests()
+
+ def fin():
+ site.rm_if_not_reusing()
+ request.addfinalizer(fin)
+
+ return site
+
+
diff --git a/tests/livestatus/test_livestatus.py b/tests/livestatus/test_livestatus.py
index 3d3cf1e6..670ad19 100644
--- a/tests/livestatus/test_livestatus.py
+++ b/tests/livestatus/test_livestatus.py
@@ -2,7 +2,7 @@
# encoding: utf-8
import pytest
-from testlib import site, web
+from testlib import web
@pytest.fixture(scope="module")
def default_cfg(web):
diff --git a/tests/omd/test_python.py b/tests/omd/test_python.py
index bcd06bb..918376f 100644
--- a/tests/omd/test_python.py
+++ b/tests/omd/test_python.py
@@ -5,8 +5,6 @@ import os
import sys
import subprocess
-from testlib import site
-
def test_01_python_interpreter_exists(site):
assert os.path.exists(site.root + "/bin/python")
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 5d4d544..e872bce 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -11,7 +11,6 @@ import requests
import socket
import pipes
import subprocess
-import livestatus
try:
import simplejson as json
@@ -157,6 +156,7 @@ class Site(object):
@property
def live(self):
+ import livestatus
live = livestatus.SingleSiteConnection("tcp:127.0.0.1:%d" %
self.livestatus_port)
live.set_timeout(2)
@@ -275,39 +275,6 @@ class Site(object):
-(a)pytest.fixture(scope="session")
-def site(request):
- def site_id():
- site_id = os.environ.get("SITE")
- if site_id == None:
- site_id = file(repo_path() + "/.site").read().strip()
-
- return site_id
-
- def site_version():
- return os.environ.get("VERSION", CMKVersion.DEFAULT)
-
- def site_edition():
- return os.environ.get("EDITION", CMKVersion.CEE)
-
- def reuse_site():
- return os.environ.get("REUSE", "1") == "1"
-
- site = Site(site_id=site_id(), version=site_version(),
- edition=site_edition(), reuse=reuse_site())
- site.cleanup_if_wrong_version()
- site.create()
- site.open_livestatus_tcp()
- site.start()
- site.prepare_for_tests()
-
- def fin():
- site.rm_if_not_reusing()
- request.addfinalizer(fin)
-
- return site
-
-
class WebSession(requests.Session):
transids = {}
diff --git a/tests/web/test_crawl.py b/tests/web/test_crawl.py
index 6cf01c9..4c615b8 100644
--- a/tests/web/test_crawl.py
+++ b/tests/web/test_crawl.py
@@ -13,7 +13,7 @@ import traceback
from urlparse import urlsplit, parse_qsl, urlunsplit, urljoin
from urllib import urlencode
from bs4 import BeautifulSoup
-from testlib import site, web, var_dir, WebSession
+from testlib import web, var_dir, WebSession
class Url(object):
diff --git a/tests/web/test_login.py b/tests/web/test_login.py
index 9804dee..c995ab0 100644
--- a/tests/web/test_login.py
+++ b/tests/web/test_login.py
@@ -2,7 +2,7 @@
# encoding: utf-8
import pytest
-from testlib import site, WebSession
+from testlib import WebSession
def test_01_login_and_logout(site):
web = WebSession(site)
diff --git a/tests/web/test_wato_webapi.py b/tests/web/test_wato_webapi.py
index 207ad31..82b2884 100644
--- a/tests/web/test_wato_webapi.py
+++ b/tests/web/test_wato_webapi.py
@@ -2,7 +2,7 @@
# encoding: utf-8
import pytest
-from testlib import site, web
+from testlib import web
def test_global_settings(site, web):
r = web.get(site.url + "wato.py")