A couple small test improvements
If the build history assertion fails, log the details of the historic
build.
Make the use of fixtures.TempDir optional, and if we are not using the
fixtures (which will be automatically deleted after the test run), use
tempfile.mkdtemp so that every ZuulTestCase object gets a unique
directory under the ZUUL_TEST_ROOT path to avoid collisions between
concurrent tests. Additionally, if we are not using fixtures, also set
LaunchServer.keep_jobdir = True.
Change-Id: Ie9a46d0a4b5b075ca2776bbd4667117aebc1a9df
diff --git a/tests/base.py b/tests/base.py
index 3ccc872..57742f8 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -66,7 +66,8 @@
FIXTURE_DIR = os.path.join(os.path.dirname(__file__),
'fixtures')
-USE_TEMPDIR = True
+
+KEEP_TEMPDIRS = bool(os.environ.get('KEEP_TEMPDIRS', False))
def repack_repo(path):
@@ -1203,12 +1204,13 @@
self.setupZK()
- if USE_TEMPDIR:
+ if not KEEP_TEMPDIRS:
tmp_root = self.useFixture(fixtures.TempDir(
rootdir=os.environ.get("ZUUL_TEST_ROOT"))
).path
else:
- tmp_root = os.environ.get("ZUUL_TEST_ROOT")
+ tmp_root = tempfile.mkdtemp(
+ dir=os.environ.get("ZUUL_TEST_ROOT", None))
self.test_root = os.path.join(tmp_root, "zuul-test")
self.upstream_root = os.path.join(self.test_root, "upstream")
self.merger_src_root = os.path.join(self.test_root, "merger-git")
@@ -1297,7 +1299,8 @@
self.config, self.connections,
jobdir_root=self.test_root,
_run_ansible=self.run_ansible,
- _test_root=self.test_root)
+ _test_root=self.test_root,
+ keep_jobdir=KEEP_TEMPDIRS)
self.launch_server.start()
self.history = self.launch_server.build_history
self.builds = self.launch_server.running_builds
@@ -1743,7 +1746,8 @@
for i, d in enumerate(history):
if not matches(self.history[i], d):
raise Exception(
- "Element %i in history does not match" % (i,))
+ "Element %i in history does not match %s" %
+ (i, self.history[i]))
else:
unseen = self.history[:]
for i, d in enumerate(history):