-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
32 lines (24 loc) · 939 Bytes
/
conftest.py
File metadata and controls
32 lines (24 loc) · 939 Bytes
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
"""Root pytest hooks for suite markers and default selection behavior."""
from pathlib import Path
suffix = "-tests"
def pytest_collection_modifyitems(config, items):
"""
Mark tests by suite based on their parent directory convention ({suite}-tests).
"""
deselect_e2e_by_default = not (config.option.markexpr or "").strip()
selected_items = []
deselected_items = []
for item in items:
pathstr = str(item.fspath)
for part in Path(pathstr).parts:
if part.endswith(suffix):
marker = part.removesuffix(suffix)
item.add_marker(marker)
break
if deselect_e2e_by_default and item.get_closest_marker("e2e"):
deselected_items.append(item)
continue
selected_items.append(item)
if deselected_items:
config.hook.pytest_deselected(items=deselected_items)
items[:] = selected_items