-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
35 lines (27 loc) · 1.23 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
import pytest
def pytest_addoption(parser):
parser.addoption("--integration", action="store_true",
default=False, help="run integration tests.")
parser.addoption("--ip", action="store", default=False,
help="Specify the ip of the server to run the integration "
"test against.")
parser.addoption("--all", action="store_true", default=False,
help="run both unit and integration tests.")
def pytest_collection_modifyitems(config, items):
if config.getoption("--all"):
return
collected_tests = items
if config.getoption("--integration"):
_run_only_integration_tests(collected_tests)
else:
_run_only_unit_tests(collected_tests)
def _run_only_unit_tests(collected_tests):
skip_marker = pytest.mark.skip(reason="need '--integration' option to run")
for test in collected_tests:
if "integration" in test.keywords:
test.add_marker(skip_marker)
def _run_only_integration_tests(collected_tests):
skip_marker = pytest.mark.skip(reason="running only integration tests.")
for test in collected_tests:
if "integration" not in test.keywords:
test.add_marker(skip_marker)