Skip to content

get_marker doesn't work for parametrized tests using custom markers #3605

@petr-balogh

Description

@petr-balogh

When we are using parametrize regarding to doc and in pytest hook pytest_collection_modifyitems we would like to get marker and it's value we are failing with error:
ValueError: MarkInfo expects Mark instances, got MarkDecorator(mark=Mark(name='custom_mark', args=('custom mark1',), kwargs={})) (<class '_pytest.mark.structures.MarkDecorator'>)

How to reproduce:
I attached full example,, you just need to run_test.sh script.

test_file.py:

import pytest

first_custom_mark = pytest.mark.custom_marker
custom_mark = pytest.mark.custom_mark

@custom_mark("custom mark non parametrized")
def test_custom_mark_non_parametrized():
    print "Hey from test"

@pytest.mark.parametrize(
    "obj_type",
    [
        first_custom_mark("first custom mark")("template"),
        pytest.param( # Think this should be recommended way?
            "disk",
            marks=custom_mark('custom mark1')
        ),
        custom_mark("custom mark2")("vm"),  # Tried also this
    ]
)
def test_custom_mark_parametrized(obj_type):
    print "obj_type is: %s" % obj_type

conftest.py

def pytest_collection_modifyitems(session, config, items):
    for item in items:
        # here we are failing with:
        # INTERNALERROR> ValueError: MarkInfo expects Mark instances, got
        # MarkDecorator(mark=Mark(name='custom_mark', args=('custom mark1',), kwargs={})) (<class '_pytest.mark.structures.MarkDecorator'>)
        custom_mark = item.get_marker('custom_mark')
        print("Custom mark %s" % custom_mark)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: marksrelated to marks, either the general marks or builtintype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions