From 2780ee190da412eabb46920ab2bbc42049303440 Mon Sep 17 00:00:00 2001 From: florian Date: Thu, 14 Jul 2022 14:27:18 +0200 Subject: [PATCH] tests - add debug_fail function --- tests/AutoconfTest.py | 7 ++++++- tests/DockerTest.py | 4 ++++ tests/Test.py | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/AutoconfTest.py b/tests/AutoconfTest.py index 1db50e687..24e2ac946 100644 --- a/tests/AutoconfTest.py +++ b/tests/AutoconfTest.py @@ -116,4 +116,9 @@ class AutoconfTest(Test) : log("AUTOCONF", "❌", "exception while running AutoconfTest._cleanup_test()\n" + format_exc()) return False return True - \ No newline at end of file + + def _debug_fail(self) : + autoconf = "/tmp/autoconf" + proc = run("docker-compose logs", shell=True, cwd=autoconf) + test = "/tmp/tests/" + self._name + proc = run("docker-compose -f autoconf.yml logs", shell=True, cwd=test) \ No newline at end of file diff --git a/tests/DockerTest.py b/tests/DockerTest.py index ed57e9357..16275a3e0 100644 --- a/tests/DockerTest.py +++ b/tests/DockerTest.py @@ -75,4 +75,8 @@ class DockerTest(Test) : log("DOCKER", "❌", "exception while running DockerTest._cleanup_test()\n" + format_exc()) return False return True + + def _debug_fail(self) : + test = "/tmp/tests/" + self._name + proc = run("docker-compose logs", shell=True, cwd=test) \ No newline at end of file diff --git a/tests/Test.py b/tests/Test.py index 75dbac116..7a9f9ac29 100644 --- a/tests/Test.py +++ b/tests/Test.py @@ -86,6 +86,7 @@ class Test(ABC) : return self._cleanup_test() log("TEST", "⚠️", "tests not ok, retrying in 1s ...") sleep(1) + self._debug_fail() log("TEST", "❌", "failed (timeout = " + str(self.__timeout) + "s)") return False @@ -100,10 +101,14 @@ class Test(ABC) : r = get(ex_url, timeout=5) return test["string"].casefold() in r.text.casefold() except : - log("TEST", "❌", "exception while running test of type " + test["type"] + " on URL " + test["url"] + "\n" + format_exc()) + log("TEST", "❌", "exception while running test of type " + test["type"] + " on URL " + ex_url + "\n" + format_exc()) return False raise(Exception("unknow test type " + test["type"])) + # called when tests fail : typical case is to show logs + def _debug_fail(self) : + pass + def _replace_in_file(self, path, old, new) : with open(path, "r") as f : content = f.read()