New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
norbertpy opened this Issue Jul 29, 2015 · 7 comments

Comments

Projects
4 participants
@norbertpy

norbertpy commented Jul 29, 2015

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)
@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Jul 29, 2015

I could reproduce the problem in master, thanks for reporting it.

It seems related to markers applied to classes (I updated the title to match this).

@nicoddemus nicoddemus changed the title from `request.node.get_marker('name')` returns `None` regardless of applied marker to `request.node.get_marker('name')` returns `None` for markers applied in classes Jul 29, 2015

@norbertpy

This comment has been minimized.

norbertpy commented Jul 29, 2015

@nicoddemus , thank you. Do I get notified if it's fixed?

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Jul 29, 2015

Yes, you're watching this thread because you submitted this issue. 😄

Thanks again.

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Jul 30, 2015

this issue is related to marker transfers

i believe the most correct fix would be implementing #891 however it comes with compatibility issues

@The-Compiler

This comment has been minimized.

Member

The-Compiler commented Aug 5, 2016

Removing the milestone here, as this shouldn't block 3.0 and we have #1670 (where I set the milestone to 4.0 for now) to track all marker staining related issues.

@The-Compiler The-Compiler removed this from the 3.0 milestone Aug 5, 2016

@RonnyPfannschmidt RonnyPfannschmidt moved this from todo to triage in resolve the mark fallout Jun 23, 2017

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Jun 23, 2017

this one can be solved after #2522

@RonnyPfannschmidt RonnyPfannschmidt moved this from triage to todo in resolve the mark fallout Jun 23, 2017

@RonnyPfannschmidt RonnyPfannschmidt moved this from todo to in progress in resolve the mark fallout Mar 27, 2018

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Apr 10, 2018

fixed in #3317

@RonnyPfannschmidt RonnyPfannschmidt moved this from in progress to done in resolve the mark fallout Apr 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment