| 24 | |
| 25 | @pytest.fixture(scope="session") |
| 26 | def test_base_dir(): |
| 27 | d = os.getenv("TEST_DIR", "/tmp") |
| 28 | |
| 29 | directory = tempfile.mkdtemp(prefix='ltests-', dir=d) |
| 30 | print("Running tests in {}".format(directory)) |
| 31 | |
| 32 | yield directory |
| 33 | |
| 34 | # Now check if any test directory is left because the corresponding test |
| 35 | # failed. If there are no such tests we can clean up the root test |
| 36 | # directory. |
| 37 | contents = [d for d in os.listdir(directory) if os.path.isdir(os.path.join(directory, d)) and d.startswith('test_')] |
| 38 | if contents == []: |
| 39 | shutil.rmtree(directory) |
| 40 | else: |
| 41 | print("Leaving base_dir {} intact, it still has test sub-directories with failure details: {}".format( |
| 42 | directory, contents |
| 43 | )) |
| 44 | |
| 45 | |
| 46 | @pytest.fixture(autouse=True) |