-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
54 lines (45 loc) · 1.18 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
"""
Setup for Sybil.
"""
import sys
from doctest import ELLIPSIS
import pytest
from beartype import beartype
from sybil import Sybil
from sybil.parsers.rest import (
CodeBlockParser,
DocTestParser,
PythonCodeBlockParser,
)
from sybil_extras.evaluators.shell_evaluator import ShellCommandEvaluator
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)
run_code_sybil = Sybil(
parsers=[
DocTestParser(optionflags=ELLIPSIS),
PythonCodeBlockParser(),
],
patterns=["*.rst", "*.py"],
)
pytest_sybil = Sybil(
parsers=[
CodeBlockParser(
language="python",
evaluator=ShellCommandEvaluator(
args=[sys.executable, "-m", "pytest"],
tempfile_suffixes=[".py"],
pad_file=True,
write_to_file=False,
use_pty=False,
),
),
],
patterns=["*.rst"],
)
sybils = run_code_sybil + pytest_sybil
pytest_collect_file = sybils.pytest()