Skip to content

Commit 5437cba

Browse files
committed
Add autouse tmp_doctest_path fixture in conftest.py
1 parent 3546ab7 commit 5437cba

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
7+
@pytest.fixture(autouse=True)
8+
def tmp_doctest_path(request, tmp_path):
9+
"""Run doctests in isolated temp dir so outputs do not end up in repo"""
10+
# Trigger ONLY for doctestplus
11+
doctest_plugin = request.config.pluginmanager.getplugin("doctestplus")
12+
if isinstance(request.node.parent, doctest_plugin._doctest_textfile_item_cls):
13+
start_path = Path.cwd()
14+
os.chdir(tmp_path)
15+
try:
16+
yield tmp_path
17+
finally:
18+
os.chdir(start_path)
19+
else:
20+
yield

0 commit comments

Comments
 (0)