Module: check_mk
Branch: master
Commit: b98cf769e0ba64435d638183cc35f046fa3cca1d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b98cf769e0ba64…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jun 29 10:43:32 2017 +0200
Always cleanup pylint test directories
Change-Id: Idac21f872e598ccf22a85488c68e3c621a5f7647
---
tests/pylint/conftest.py | 28 ++++++++++++++++++++++++++++
tests/pylint/test_pylint_checks.py | 8 +++-----
tests/pylint/test_pylint_modules.py | 8 +++-----
tests/pylint/test_pylint_web.py | 12 +++++-------
tests/testlib/pylint_cmk.py | 25 ++++++-------------------
5 files changed, 45 insertions(+), 36 deletions(-)
diff --git a/tests/pylint/conftest.py b/tests/pylint/conftest.py
new file mode 100644
index 0000000..73231cf
--- /dev/null
+++ b/tests/pylint/conftest.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import os
+import tempfile
+import shutil
+import pytest
+
+(a)pytest.fixture(scope="session")
+def pylint_test_dir():
+ base_path = os.environ.get("WORKDIR")
+ if base_path:
+ base_path += "/" + os.path.basename(sys.argv[0])
+ if not os.path.exists(base_path):
+ os.makedirs(base_path)
+ else:
+ base_path = None
+
+ test_dir = tempfile.mkdtemp(prefix="cmk_pylint", dir=base_path)
+
+ print("Prepare check in %s ..." % test_dir)
+ yield test_dir
+
+ #
+ # Cleanup code
+ #
+
+ print("Cleanup pylint test dir %s ..." % test_dir)
+ shutil.rmtree(test_dir)
diff --git a/tests/pylint/test_pylint_checks.py b/tests/pylint/test_pylint_checks.py
index c4ab1d8..7071546 100755
--- a/tests/pylint/test_pylint_checks.py
+++ b/tests/pylint/test_pylint_checks.py
@@ -11,10 +11,8 @@ import testlib.pylint_cmk as pylint_cmk
# Mark all tests in this file to be pylint checks
pytestmark = pytest.mark.pylint
-def test_pylint_checks():
- base_path = pylint_cmk.get_test_dir()
-
- f = file(base_path + "/cmk-checks.py", "w")
+def test_pylint_checks(pylint_test_dir):
+ f = file(pylint_test_dir + "/cmk-checks.py", "w")
# add the modules
for path in pylint_cmk.ordered_module_files():
@@ -34,6 +32,6 @@ def test_pylint_checks():
f.close()
- exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True)
+ exit_code = pylint_cmk.run_pylint(pylint_test_dir)
assert exit_code == 0, "PyLint found an error in checks, inventory " \
"or agent bakery plugins"
diff --git a/tests/pylint/test_pylint_modules.py b/tests/pylint/test_pylint_modules.py
index 8fd7383..5ffb0a4 100755
--- a/tests/pylint/test_pylint_modules.py
+++ b/tests/pylint/test_pylint_modules.py
@@ -11,13 +11,11 @@ import testlib.pylint_cmk as pylint_cmk
# Mark all tests in this file to be pylint checks
pytestmark = pytest.mark.pylint
-def test_pylint_modules():
- base_path = pylint_cmk.get_test_dir()
-
- f = file(base_path + "/cmk-modules.py", "w")
+def test_pylint_modules(pylint_test_dir):
+ f = file(pylint_test_dir + "/cmk-modules.py", "w")
for path in pylint_cmk.ordered_module_files():
pylint_cmk.add_file(f, path)
f.close()
- exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True)
+ exit_code = pylint_cmk.run_pylint(pylint_test_dir)
assert exit_code == 0, "PyLint found an error in modules"
diff --git a/tests/pylint/test_pylint_web.py b/tests/pylint/test_pylint_web.py
index fc3427f..6a0749d 100755
--- a/tests/pylint/test_pylint_web.py
+++ b/tests/pylint/test_pylint_web.py
@@ -39,11 +39,9 @@ def get_plugin_files(plugin_dir):
return sorted(files)
-def test_pylint_web():
- base_path = pylint_cmk.get_test_dir()
-
+def test_pylint_web(pylint_test_dir):
# Make compiled files import eachother by default
- sys.path.insert(0, base_path)
+ sys.path.insert(0, pylint_test_dir)
modules = glob.glob(cmk_path() + "/web/htdocs/*.py") \
+ glob.glob(cmc_path() + "/web/htdocs/*.py") \
@@ -51,7 +49,7 @@ def test_pylint_web():
for module in modules:
print("Copy %s to test directory" % module)
- f = open(base_path + "/" + os.path.basename(module), "w")
+ f = open(pylint_test_dir + "/" + os.path.basename(module),
"w")
pylint_cmk.add_file(f, module)
f.close()
@@ -73,9 +71,9 @@ def test_pylint_web():
module_name = plugin_dir
print("[%s] add %s" % (module_name, plugin_path))
- module = file(base_path + "/" + module_name + ".py",
"a")
+ module = file(pylint_test_dir + "/" + module_name +
".py", "a")
pylint_cmk.add_file(module, plugin_path)
module.close()
- exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True)
+ exit_code = pylint_cmk.run_pylint(pylint_test_dir)
assert exit_code == 0, "PyLint found an error in the web code"
diff --git a/tests/testlib/pylint_cmk.py b/tests/testlib/pylint_cmk.py
index f0e806d..6fcda12 100644
--- a/tests/testlib/pylint_cmk.py
+++ b/tests/testlib/pylint_cmk.py
@@ -80,20 +80,7 @@ def add_file(f, path):
f.write(file(path).read())
-def get_test_dir():
- base_path = os.environ.get("WORKDIR")
- if base_path:
- base_path += "/" + os.path.basename(sys.argv[0])
- if not os.path.exists(base_path):
- os.makedirs(base_path)
- else:
- base_path = tempfile.mkdtemp(prefix="cmk_pylint")
-
- print("Prepare check in %s ..." % base_path)
- return base_path
-
-
-def run_pylint(base_path, check_files=None, cleanup_test_dir=False):
+def run_pylint(base_path, check_files=None): #, cleanup_test_dir=False):
pylint_args = os.environ.get("PYLINT_ARGS", "")
if pylint_args:
pylint_args += " "
@@ -112,11 +99,11 @@ def run_pylint(base_path, check_files=None, cleanup_test_dir=False):
exit_code = p.wait()
print("Finished with exit code: %d" % exit_code)
- if exit_code == 0 and cleanup_test_dir:
- # Don't remove directory when specified via WORKDIR env
- if not os.environ.get("WORKDIR"):
- print("Removing build path...")
- shutil.rmtree(base_path)
+ #if exit_code == 0 and cleanup_test_dir:
+ # # Don't remove directory when specified via WORKDIR env
+ # if not os.environ.get("WORKDIR"):
+ # print("Removing build path...")
+ # shutil.rmtree(base_path)
return exit_code