pytest AttributeError: 'Function' object has no attribute 'get_marker'
Pytest has changed its API in version 4.
Quick solution: use get_closest_marker()
instead of get_marker()
:
def pytest_collection_modifyitems(config, items):
items.sort(key=lambda x: 2 if x.get_closest_marker('slow') else 1)
See https://github.com/pytest-dev/pytest/pull/4564
Remove
Node.get_marker(name)
the return value was not usable for more than a existence check.Use
Node.get_closest_marker(name)
as a replacement.Remove
testfunction.markername
attributes - useNode.iter_markers(name=None)
to iterate them.