-
Notifications
You must be signed in to change notification settings - Fork 679
/
Copy pathconftest.py
61 lines (48 loc) · 1.63 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
55
56
57
58
59
60
61
import os
import pytest
def pytest_addoption(parser):
parser.addoption("--only-stable", action="store_true", help="run only stable tests")
parser.addoption(
"--skip-requires-api-key",
action="store_true",
help="skip tests that require an API key",
)
parser.addoption(
"--strict-data-files",
action="store_true",
help="Fail if a test is skipped for missing data file.",
)
def pytest_runtest_setup(item):
if "stable" not in item.keywords and item.config.getoption("--only-stable"):
pytest.skip("skipping due to --only-stable")
if "requires_api_key" in item.keywords and item.config.getoption(
"--skip-requires-api-key"
):
pytest.skip("skipping due to --skip-requires-api-key")
@pytest.fixture
def datapath(request):
"""Get the path to a data file.
Parameters
----------
path : str
Path to the file, relative to ``pandas/tests/``
Returns
-------
path : path including ``pandas/tests``.
Raises
------
ValueError
If the path doesn't exist and the --strict-data-files option is set.
"""
BASE_PATH = os.path.join(os.path.dirname(__file__), "tests")
def deco(*args):
path = os.path.join(BASE_PATH, *args)
if not os.path.exists(path):
if request.config.getoption("--strict-data-files"):
msg = "Could not find file {} and --strict-data-files is set."
raise ValueError(msg.format(path))
else:
msg = "Could not find {}."
pytest.skip(msg.format(path))
return path
return deco