-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
60 lines (45 loc) · 1.99 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
"""conftest.py.
This file contains the test configuration for the whole test suite.
Within the pytest_addoption function, the markers can be configured, ready to add
to specific tests. Any tests marked with these markers will be skipped by default
(if default=False). To call these tests with pytest, add the command line argument
'-m --{marker}'.
To mark a test, use pytest.mark.{marker}.
When setting up a new marker, the 'pytest_collection_modifyitems' and
'pytest_configure' functions must be updated accordingly.
`pytest` configuration file. Currently used to flag tests for set-up only.
Reworked example from pytest docs:
https://docs.pytest.org/en/latest/example/simple.html.
"""
import pytest
def pytest_addoption(parser):
"""Adapt pytest cli args, and give more info when -h flag is used."""
parser.addoption(
"--runhdfs",
action="store_true",
default=False,
help="Run HDFS tests.",
)
parser.addoption(
"--runwip", action="store_true", default=False, help="Run WIP tests."
)
def pytest_configure(config):
"""Add ini value line."""
config.addinivalue_line("markers", "runhdfs: Run HDFS related tests.")
config.addinivalue_line("markers", "runwip: Run work in progress tests.")
def pytest_collection_modifyitems(config, items): # noqa:C901
"""Handle switching based on cli args."""
# do full test suite when all flags are given
if config.getoption("--runhdfs") & config.getoption("--runwip"):
return
# do not add marks when the markers flags are passed
if not config.getoption("--runhdfs"):
skip_hdfs = pytest.mark.skip(reason="Need --runhdfs option to run.")
for item in items:
if "runhdfs" in item.keywords:
item.add_marker(skip_hdfs)
if not config.getoption("--runwip"):
skip_hdfs = pytest.mark.skip(reason="Need --runwip option to run.")
for item in items:
if "runwip" in item.keywords:
item.add_marker(skip_hdfs)