From e00c7012cc29264be145739fb191bf531eb964aa Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sat, 5 May 2018 15:30:14 +0200 Subject: [PATCH] pytest: Ensure unique test directories per test even if rerun We add an attempt number to the test directory to improve the test-isolation and allow for multiple reruns of the same test, without re-using any of the lightning-dirs or bitcoin-datadirs. Signed-off-by: Christian Decker --- tests/fixtures.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/fixtures.py b/tests/fixtures.py index d00635c4a..5b939e920 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -15,12 +15,22 @@ DEVELOPER = os.getenv("DEVELOPER", "0") == "1" TEST_DEBUG = os.getenv("TEST_DEBUG", "0") == "1" +# A dict in which we count how often a particular test has run so far. Used to +# give each attempt its own numbered directory, and avoid clashes. +__attempts = {} + + @pytest.fixture def directory(test_name): - """Return a per-test specific directory + """Return a per-test specific directory. + + This makes a unique test-directory even if a test is rerun multiple times. + """ - global TEST_DIR - yield os.path.join(TEST_DIR, test_name) + global TEST_DIR, __attempts + # Auto set value if it isn't in the dict yet + __attempts[test_name] = __attempts.get(test_name, 0) + 1 + yield os.path.join(TEST_DIR, "{}_{}".format(test_name, __attempts[test_name])) @pytest.fixture