-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
47 lines (37 loc) · 1.37 KB
/
conftest.py
File metadata and controls
47 lines (37 loc) · 1.37 KB
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
"""Configuration for pytest."""
import pytest
def pytest_addoption(parser: pytest.Parser) -> None:
"""Add command line options for pytest.
References
----------
.. [1] https://docs.pytest.org/en/stable/example/simple.html#control-skipping-of-tests-according-to-command-line-option
"""
parser.addoption(
"--slow",
action="store_true",
default=False,
help="Run long-running tests",
)
def pytest_configure(config: pytest.Config) -> None:
"""Configure pytest with custom markers.
References
----------
.. [1] https://docs.pytest.org/en/stable/example/simple.html#control-skipping-of-tests-according-to-command-line-option
"""
config.addinivalue_line("markers", "slow: mark test as slow to run")
def pytest_collection_modifyitems(
config: pytest.Config,
items: list[pytest.Item],
) -> None:
"""Modify collected test items to skip slow tests unless --slow is given.
References
----------
.. [1] https://docs.pytest.org/en/stable/example/simple.html#control-skipping-of-tests-according-to-command-line-option
"""
if config.getoption("--slow"):
# --slow given in cli: do not skip slow tests
return
skip_slow = pytest.mark.skip(reason="need --slow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)