-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconftest.py
55 lines (41 loc) · 1.47 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
49
50
51
52
53
54
55
"""Conftest.py (root-level).
We keep this in root pytest fixtures in pytest's doctest plugin to be available, as well
as avoiding conftest.py from being included in the wheel, in addition to pytest_plugin
for pytester only being available via the root directory.
See "pytest_plugins in non-top-level conftest files" in
https://docs.pytest.org/en/stable/deprecations.html
"""
from __future__ import annotations
import shutil
import typing as t
import pytest
from _pytest.doctest import DoctestItem
from unihan_etl.pytest_plugin import USING_ZSH
if t.TYPE_CHECKING:
import pathlib
pytest_plugins = ["pytester"]
@pytest.fixture(autouse=True)
def add_doctest_fixtures(
request: pytest.FixtureRequest,
doctest_namespace: dict[str, t.Any],
) -> None:
"""Harness pytest fixtures to doctest namespace."""
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):
request.getfixturevalue("set_home")
doctest_namespace["request"] = request
@pytest.fixture(autouse=True)
def set_home(
monkeypatch: pytest.MonkeyPatch,
unihan_user_path: pathlib.Path,
) -> None:
"""Set home directory for pytest tests."""
monkeypatch.setenv("HOME", str(unihan_user_path))
@pytest.fixture(autouse=True, scope="session")
def setup(
request: pytest.FixtureRequest,
unihan_ensure_quick: None,
unihan_ensure_full: None,
) -> None:
"""Configure test fixtures for pytest."""
if USING_ZSH:
request.getfixturevalue("unihan_zshrc")