Description
Originally reported by: Alexander Steinert (BitBucket: stony8, GitHub: stony8)
Scattering a custom marker registration/defintion/usage to different
hook functions -- like done in
http://pytest.org/latest/example/markers.html#custom-marker-and-command-line-option-to-control-test-runs --
does not scale well to multiple markers.
I would prefer to define a custom marker as a function that gets called at
collection time for each marked test. Example:
#!python
import re
import pytest
@pytest.marker
def verifies(requirement):
"""mark test as verifying a requirement"""
assert re.search(r"^http://myjira/browse/PROJ-\d+$", requirement)
@pytest.mark.verifies("http://myjira/browse/PROJ-42")
def test_42():
assert 6 * 8 != 42
With the decorator pytest.marker we could avoid calling
config.addinivalue_line("markers", ...) and be able to check marker arguments.
The arguments should be available in hooks, e.g.
#!python
item.keywords["verifies"].getarg("requirement").
Holger has an unfinished patch which allows roughly the above. His decorator is
called pytest.markdefinition. I would prefer pytest.marker but thats just a
matter of taste.