-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
40 lines (29 loc) · 1.06 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
import shutil
import pytest
import arcadia_pycolor as apc
def pytest_addoption(parser):
"""
Add custom CLI options for pytest.
Note: this function is a pytest hook and it must appear in a file named `conftest.py`
in the root directory of the project.
"""
parser.addoption(
"--output-dirpath",
dest="output_dirpath",
default=None,
help="Path to a directory in which to save the plots generated by the tests.",
)
@pytest.fixture(scope="session", autouse=True)
def setup_matplotlib():
apc.mpl.setup()
@pytest.fixture(scope="session")
def output_dirpath(pytestconfig, tmp_path_factory):
"""
Return the path to the directory in which to save the output of the tests.
"""
tmp_path = tmp_path_factory.mktemp("output")
yield tmp_path
user_provided_output_dirpath = pytestconfig.getoption("output_dirpath")
if user_provided_output_dirpath is not None:
shutil.rmtree(user_provided_output_dirpath, ignore_errors=True)
shutil.copytree(tmp_path, user_provided_output_dirpath)