Pytest: [Question] : Is there a way to find all markers associated with a particular test function?

Created on 1 Aug 2018  路  3Comments  路  Source: pytest-dev/pytest

Is it possible to collect all the markers that are used with a particular test function along with marker arguments?

@pytest.mark.m1('abc')
@pytest.mark.skipif('True')
def test_1():
    pass

I can collect all the tests with a particular marker using --collect-only -m marker_name.
However given a test function eg. test_1 I want the list of markers i.e. [m1('abc') , skipif('True')].

Thanks in advance!

marks question

Most helpful comment

@thakkardharmik there is no cli option to do it,

but given the test items for the makers you can do list(item.iter_markers()) or list(item.iter_markers_with_node())

All 3 comments

@thakkardharmik there is no cli option to do it,

but given the test items for the makers you can do list(item.iter_markers()) or list(item.iter_markers_with_node())

@thakkardharmik does this resolve your issue? please follow up by closing or adding more information/questions so we can follow up thereafter

@RonnyPfannschmidt Thanks alot! This works for me.

Was this page helpful?
0 / 5 - 0 ratings