-
Notifications
You must be signed in to change notification settings - Fork 24
/
conftest.py
50 lines (40 loc) · 1.43 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
"""Doctest configuration."""
from doctest import ELLIPSIS, NORMALIZE_WHITESPACE
import pytest
from sybil import Sybil
from sybil.parsers.myst import DocTestDirectiveParser as MarkdownDocTestParser
from sybil.parsers.myst import PythonCodeBlockParser as MarkdownPythonCodeBlockParser
from sybil.parsers.myst import SkipParser as MarkdownSkipParser
from sybil.parsers.rest import DocTestParser as ReSTDocTestParser
from sybil.parsers.rest import PythonCodeBlockParser as ReSTPythonCodeBlockParser
from sybil.parsers.rest import SkipParser as ReSTSkipParser
OPTIONS = ELLIPSIS | NORMALIZE_WHITESPACE
@pytest.fixture(scope="module")
def use_clean_dispatcher():
import plum
# Save the original dispatcher.
dispatcher = plum.dispatch
# Swap the dispatcher with a temporary one.
temp_dispatcher = plum.Dispatcher()
plum.dispatch = temp_dispatcher
yield
# Restore the original dispatcher.
plum.dispatch = dispatcher
markdown_examples = Sybil(
parsers=[
MarkdownDocTestParser(optionflags=OPTIONS),
MarkdownPythonCodeBlockParser(doctest_optionflags=OPTIONS),
MarkdownSkipParser(),
],
patterns=["*.md"],
fixtures=["use_clean_dispatcher"],
)
rest_examples = Sybil(
parsers=[
ReSTDocTestParser(optionflags=OPTIONS),
ReSTPythonCodeBlockParser(),
ReSTSkipParser(),
],
patterns=["*.py"],
)
pytest_collect_file = (markdown_examples + rest_examples).pytest()