-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
71 lines (59 loc) · 1.92 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Setup for test suite.
"""
import uuid
from collections.abc import Generator
from doctest import ELLIPSIS
import pytest
from beartype import beartype
from mock_vws import MockVWS
from mock_vws.database import VuforiaDatabase
from sybil import Sybil
from sybil.parsers.rest import (
CaptureParser,
DocTestParser,
PythonCodeBlockParser,
)
@pytest.fixture(name="mock_vws")
def fixture_mock_vws(
monkeypatch: pytest.MonkeyPatch,
) -> Generator[None]:
"""Yield a mock VWS.
The keys used here match the keys in the documentation.
"""
server_access_key = uuid.uuid4().hex
server_secret_key = uuid.uuid4().hex
client_access_key = uuid.uuid4().hex
client_secret_key = uuid.uuid4().hex
database = VuforiaDatabase(
server_access_key=server_access_key,
server_secret_key=server_secret_key,
client_access_key=client_access_key,
client_secret_key=client_secret_key,
)
monkeypatch.setenv(name="VWS_SERVER_ACCESS_KEY", value=server_access_key)
monkeypatch.setenv(name="VWS_SERVER_SECRET_KEY", value=server_secret_key)
monkeypatch.setenv(name="VWS_CLIENT_ACCESS_KEY", value=client_access_key)
monkeypatch.setenv(name="VWS_CLIENT_SECRET_KEY", value=client_secret_key)
# We use a low processing time so that tests run quickly.
with MockVWS(processing_time_seconds=0.2) as mock:
mock.add_database(database=database)
yield
sybil_obj = Sybil(
parsers=[
DocTestParser(optionflags=ELLIPSIS),
PythonCodeBlockParser(),
CaptureParser(),
],
patterns=["*.rst", "*.py"],
fixtures=["mock_vws"],
)
pytest_collect_file = sybil_obj.pytest()
@beartype
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
"""
Apply the beartype decorator to all collected test functions.
"""
for item in items:
if isinstance(item, pytest.Function):
item.obj = beartype(obj=item.obj)