-
Notifications
You must be signed in to change notification settings - Fork 24
/
conftest.py
54 lines (44 loc) · 1.34 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
"""Doctest configuration."""
from doctest import ELLIPSIS, NORMALIZE_WHITESPACE
import pytest
from sybil import Sybil
from sybil.parsers.myst import (
DocTestDirectiveParser as MarkdownDocTestParser,
PythonCodeBlockParser as MarkdownPythonCodeBlockParser,
SkipParser as MarkdownSkipParser,
)
from sybil.parsers.rest import (
DocTestParser as ReSTDocTestParser,
PythonCodeBlockParser as ReSTPythonCodeBlockParser,
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()