[pytest-dev] Accessing markers in pytest_generate_tests

Nikolaus Rath Nikolaus at rath.org
Fri Sep 21 07:44:13 EDT 2018


Hello,

I am currently using code like this:

def pytest_generate_tests(metafunc, _info_cache=[]):
    # [...]
    
    fn = metafunc.function
  
    do_something(fn.with_backend.kwargs)
    for spec in fn.with_backend.args:
       # [...]

This has started to emit a warning:

/home/nikratio/in-progress/s3ql/tests/t1_backends.py:118: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
Please use node.get_closest_marker(name) or node.iter_markers(name).
Docs: https://docs.pytest.org/en/latest/mark.html#updating-code
  for spec in fn.with_backend.args:


In my case, the correction solution seems to be to use the
get_closest_marker() method instead. However, this is defined for Node -
neither the metafunc nor the metafunc.function objects have such a
method.

What's the recommended way to access markers in pytest_generate_tests?

Best,
-Nikolaus


-- 
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«


More information about the pytest-dev mailing list