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 143
/
conftest.py
43 lines (35 loc) · 1.68 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
# ------------------------------------------------------------------------------------------
# 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.fixed_paths import add_submodules_to_path
from InnerEye.Common.fixed_paths_for_tests import TEST_OUTPUTS_PATH
from InnerEye.Common.output_directories import OutputFolderForTests, remove_and_create_folder
# This needs to be right at the start of conftest, so that already test collection has access to all submodules
add_submodules_to_path()
@pytest.fixture(autouse=True, scope='session')
def test_suite_setup() -> Generator:
# create a default outputs root for all tests
remove_and_create_folder(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 = TEST_OUTPUTS_PATH / str(uuid.uuid4().hex)
remove_and_create_folder(root_dir)
print(f"Created temporary folder for test: {root_dir}")
# let the test function run
yield OutputFolderForTests(root_dir=root_dir)