Skip to content

Commit 92e64c6

Browse files
authored
TST: use sybil for doctests (#159)
* TST: use sybil for doctests * Fix docs * Remove unneeded whitespace normalization * Try to fix tests under Mac * Try to fix Windows * Provide imports in namespace * Fix checking for Windows * Make sure user docs are checked
1 parent f362f45 commit 92e64c6

File tree

10 files changed

+201
-204
lines changed

10 files changed

+201
-204
lines changed

audeer/core/conftest.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1+
from doctest import ELLIPSIS
2+
import os
3+
import platform
4+
15
import pytest
6+
import sybil
7+
from sybil.parsers.rest import DocTestParser
8+
from sybil.parsers.rest import SkipParser
29

310
import audeer
411

512

6-
@pytest.fixture(autouse=True)
7-
def docdir(doctest_namespace, request):
8-
# make sure audeer is imported
9-
doctest_namespace["audeer"] = audeer
10-
# set temporal working directory in docstring examples
11-
tmpdir = request.getfixturevalue("tmpdir")
12-
with tmpdir.as_cwd():
13-
yield
13+
def imports(namespace):
14+
"""Provide Python modules to namespace."""
15+
namespace["platform"] = platform
16+
namespace["audeer"] = audeer
17+
18+
19+
@pytest.fixture(scope="function")
20+
def run_in_tmpdir(tmpdir_factory):
21+
"""Move to a persistent tmpdir for execution of a whole file."""
22+
tmpdir = tmpdir_factory.mktemp("tmp")
23+
current_dir = os.getcwd()
24+
os.chdir(tmpdir)
25+
26+
yield
27+
28+
os.chdir(current_dir)
29+
30+
31+
# Collect doctests
32+
pytest_collect_file = sybil.Sybil(
33+
parsers=[DocTestParser(optionflags=ELLIPSIS), SkipParser()],
34+
patterns=["*.py"],
35+
fixtures=["run_in_tmpdir"],
36+
setup=imports,
37+
).pytest()

0 commit comments

Comments
 (0)