mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-05 07:14:36 +01:00
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 <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
71857bad8e
commit
e00c7012cc
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user