-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconftest.py
More file actions
27 lines (19 loc) · 797 Bytes
/
Copy pathconftest.py
File metadata and controls
27 lines (19 loc) · 797 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
"""Custom configuration of pytest."""
# Standard library imports
import pathlib
# Third party imports
import pytest
def pytest_configure(config):
"""Add custom markers from the configuration."""
years = [p.name for p in pathlib.Path(__file__).parent.glob("2*")]
for year in years:
config.addinivalue_line("markers", f"year{year}: Puzzles for year {year}")
def pytest_collection_modifyitems(config, items):
"""Add marks based the year of the puzzle."""
for item in items:
try:
year = item.callspec.getparam("puzzle_path").parent.name
except (AttributeError, ValueError):
year = pathlib.Path(item.fspath.dirname).parent.name
if year.startswith("2"):
item.add_marker(getattr(pytest.mark, f"year{year}"))