Skip to content

request.node.get_marker('name') returns None for markers applied in classes #902

Closed
@norbertpy

Description

@norbertpy

I don't know why, but I can't get the marker from my fixture. The request.node.get_marker() seems to return None regardless of the marker applied to class:

    @pytest.fixture(scope='class')
    def my_fixture(request):
        marker = request.node.get_marker('joe') # Is always None


    @pytest.mark.joe
    class TestMarker(object):

        def test_marker(self, my_fixture):
            assert True

I even registered the marker in my pytest.ini file:

    # content of pytest.ini
    [pytest]
    markers =
        joe: mark a test as joejoejoe

Is this a bug or I'm missing something? Not to mention, I'm using 2.7.2 version.

Update 1:

If I get rid of the class and apply the marker to a function, it'll work:

@pytest.mark.joe
def test_marker(my_fixture):
    assert True

Update 2:

This actually works:

@pytest.fixture(scope='class')
def my_fixture(request):
    marker = next((m for m in request.cls.pytestmark if m.name == 'joe'), None)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: marksrelated to marks, either the general marks or builtintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions