Skip to content

Markers as functions #277

Closed
Closed
@pytestbot

Description

@pytestbot

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.


Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions