This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
conftest.py
48 lines (38 loc) · 1.7 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# ------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
# ------------------------------------------------------------------------------------------
"""
Global PyTest configuration -- used to define global fixtures for the entire test suite
DO NOT RENAME THIS FILE: (https://docs.pytest.org/en/latest/fixture.html#sharing-a-fixture-across-tests-in-a-module
-or-class-session)
"""
import uuid
from typing import Generator
import pytest
from InnerEye.Common.output_directories import TestOutputDirectories, make_test_output_dir
from Tests.fixed_paths_for_tests import TEST_OUTPUTS_PATH
@pytest.fixture(autouse=True, scope='session')
def test_suite_setup() -> Generator:
# create a default outputs root for all tests
make_test_output_dir(TEST_OUTPUTS_PATH)
# run the entire test suite
yield
@pytest.fixture
def test_output_dirs() -> Generator:
"""
Fixture to automatically create a random directory before executing a test and then
removing this directory after the test has been executed.
"""
# create dirs before executing the test
root_dir = make_output_dirs_for_test()
print(f"Created temporary folder for test: {root_dir}")
# let the test function run
yield TestOutputDirectories(root_dir=root_dir)
def make_output_dirs_for_test() -> str:
"""
Create a random output directory for a test inside the global test outputs root.
"""
test_output_dir = TEST_OUTPUTS_PATH / str(uuid.uuid4().hex)
make_test_output_dir(test_output_dir)
return str(test_output_dir)