forked from asdf-format/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
32 lines (25 loc) · 901 Bytes
/
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
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-
import os
import pytest
from _pytest.doctest import DoctestItem
from astropy.tests.helper import enable_deprecations_as_exceptions
enable_deprecations_as_exceptions()
@pytest.fixture(autouse=True)
def _docdir(request):
"""
Make sure that doctests run in a temporary directory so that any files that
are created as part of the test get removed automatically.
"""
# Trigger ONLY for the doctests.
if isinstance(request.node, DoctestItem):
# Get the fixture dynamically by its name.
tmpdir = request.getfuncargvalue('tmpdir')
# Chdir only for the duration of the test.
olddir = os.getcwd()
tmpdir.chdir()
yield
os.chdir(olddir)
else:
# For normal tests, we have to yield, since this is a yield-fixture.
yield