Browse Source

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>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
e00c7012cc
  1. 16
      tests/fixtures.py

16
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

Loading…
Cancel
Save