Access markers from pytest_generate_tests?
Hello, Is there a way to access test markers sin the pytest_generate_tests hook? For example: @pytest.mark.bla def test_one(): # ... def pytest_generate_tests(metafunc): if metafunc_has_bla_mark(metafunc): # do something But what do you have to use for metafunc_has_bla_mark? Unfortunately metafunc.function does not have a `keywords` attribute... Best, -Nikolaus -- GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F »Time flies like an arrow, fruit flies like a Banana.«
Hi Nikolaus, On Thu, Nov 27, 2014 at 15:39 -0800, Nikolaus Rath wrote:
Hello,
Is there a way to access test markers sin the pytest_generate_tests hook?
For example:
@pytest.mark.bla def test_one(): # ...
def pytest_generate_tests(metafunc): if metafunc_has_bla_mark(metafunc): # do something
But what do you have to use for metafunc_has_bla_mark? Unfortunately metafunc.function does not have a `keywords` attribute...
Right now you probably have to use hasattr(metafunc.function, "somename") but i agree that adding an API to metafunc is much better. It should be something like: metafunc.get_marker(...) which is similar to the existing: item.get_marker(...) which you can use in other hooks and contexts. best, holger
participants (2)
-
holger krekel -
Nikolaus Rath