-
Notifications
You must be signed in to change notification settings - Fork 49
/
conftest.py
52 lines (47 loc) · 1.89 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
#
# Copyright (C) 2022
# MIT
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
'''Pytest fixtures for running doctests
Pytest looks for conftest.py files that define fixtures only in the
directory tree that is being tested. When we run doctests in the
documentation only, it will therefore not find that fixtures that are
defined in sherpa/conftest.py, thus this file copies over the fixtures we
need.
'''
import pytest
from sherpa.utils.testing import get_datadir
@pytest.fixture(autouse=True)
def add_sherpa_test_data_dir(doctest_namespace):
'''Define `data_dir` for doctests
We make this an autouse=True fixture, because that means that
the variable `data_dir` is available in every file that we may
want to test without any special markup to that file. There is a
risk that this is too magical and could confuse developers
in the future, but it seems more important that this keeps any
extra markup out of those files and keep them clean.
'''
# We could error out here, but we only want the tests that
# use it to fail.
#
path = get_datadir()
if path is None:
pytest.skip("sherpa-test-data not found")
if not path.endswith('/'):
path += '/'
doctest_namespace["data_dir"] = path