-
Notifications
You must be signed in to change notification settings - Fork 668
/
conftest.py
40 lines (33 loc) · 1.14 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
"""On GH Actions windows-latest, the supplied tmpdir is on a different Drive to the CWD,
and so relative path computations fail.
Therefore, here we allow for the directory to be directly supplied,
via an environmental variable.
"""
import shutil
from pathlib import Path
from uuid import uuid4
import pytest
def pytest_addoption(parser):
"""Define pytest command-line option"""
group = parser.getgroup("jupyter_book")
group.addoption(
"--jb-tempdir",
dest="jb_tempdir",
default=None,
help="Specify a directory in which to create tempdirs",
)
def pytest_report_header(config):
path = "<TEMP>"
if config.getoption("jb_tempdir"):
path = Path(config.getoption("jb_tempdir")).absolute().as_posix()
return [f"JB TEMPDIR: {path}"]
@pytest.fixture()
def temp_with_override(pytestconfig, tmpdir):
if pytestconfig.getoption("jb_tempdir"):
path = Path(pytestconfig.getoption("jb_tempdir")).resolve().absolute()
path = path / str(uuid4())
path.mkdir(parents=True)
yield path
shutil.rmtree(path)
else:
yield Path(tmpdir.dirname) / tmpdir.basename