Skip to content

Commit 69a8128

Browse files
committed
refactor(CFMTech#46): Use markers to generate documentation.
The pytest_configure hook now uses the `PyTestMonitorMarkerProcessor` to iterate over all known markers in order to generate the documentation.
1 parent 6a17437 commit 69a8128

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

pytest_monitor/markers.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import warnings
2-
from typing import Any, Dict, List
2+
from typing import Any, Dict, Iterator, List
33

44
import pytest
55

@@ -96,6 +96,9 @@ def __init__(self):
9696
def _defaults(self) -> Dict[str, Any]:
9797
return {marker.attribute: marker.default_value for marker in self._markers}
9898

99+
def __iter__(self) -> Iterator[PyTestMonitorMarker]:
100+
return iter(self._markers)
101+
99102
def __call__(self, item: pytest.Item) -> PyTestMonitorItemConfig:
100103
item_monitor_markers: Dict[str, pytest.Mark] = {
101104
marker.name: marker for marker in item.iter_markers() if marker and marker.name.startswith("monitor_")

pytest_monitor/models.py

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def post_process(self, configuration: Dict[str, bool]) -> Dict[str, bool]:
4141
def name(self) -> str:
4242
return self._name
4343

44+
@property
45+
def require_item(self) -> bool:
46+
return self._require_item
47+
48+
@property
49+
def documentation(self) -> str:
50+
return self._doc
51+
4452
@property
4553
def deprecated(self) -> bool:
4654
return self._deprecated

pytest_monitor/pytest_monitor.py

+7-18
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,13 @@ def pytest_addoption(parser):
8787
)
8888

8989

90-
def pytest_configure(config):
91-
config.addinivalue_line("markers", "monitor_skip_test: mark test to be executed but not monitored.")
92-
config.addinivalue_line(
93-
"markers",
94-
"monitor_skip_test_if(cond): mark test to be executed but not monitored if cond is verified.",
95-
)
96-
config.addinivalue_line(
97-
"markers",
98-
"monitor_test: mark test to be monitored (default behaviour)."
99-
" This can turn handy to whitelist some test when you have disabled"
100-
" monitoring on a whole module.",
101-
)
102-
config.addinivalue_line(
103-
"markers",
104-
"monitor_test_if(cond): mark test to be monitored if and only if cond"
105-
" is verified. This can help you in whitelisting tests to be monitored"
106-
" depending on some external conditions.",
107-
)
90+
def pytest_configure(config: pytest.Config):
91+
for marker in marker_processor:
92+
marker_name = f"{marker.name}(condition)" if marker.require_item else marker.name
93+
doc = f"{marker_name}: {marker.documentation}"
94+
if marker.deprecated:
95+
doc += "Deprecated, please consult documentation to update your test."
96+
config.addinivalue_line("markers", doc)
10897

10998

11099
def pytest_runtest_setup(item: pytest.Item):

0 commit comments

Comments
 (0)