web-dev-qa-db-fra.com

Pytest AttributeError: L'objet 'Fonction' n'a aucun attribut 'get_marker'

J'ai ce code dans mon conftest.py:

def pytest_collection_modifyitems(config, items):
    items.sort(key=lambda x: 2 if x.get_marker('slow') else 1)

Dernièrement, il a commencé à provoquer ces exceptions:

$ venv/bin/py.test  -vv --tb=short tests
============================================================================ test session starts ============================================================================
platform darwin -- Python 3.5.6, pytest-4.1.1, py-1.7.0, pluggy-0.8.1 -- /Users/.../venv/bin/python3.5
cachedir: .pytest_cache
rootdir: /Users/..., inifile:
collecting ... INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/.../venv/lib/python3.5/site-packages/_pytest/main.py", line 203, in wrap_session
...
INTERNALERROR>   File "/Users/.../venv/lib/python3.5/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/.../tests/conftest.py", line 14, in pytest_collection_modifyitems
INTERNALERROR>     items.sort(key=lambda x: 2 if x.get_marker('slow') else 1)
INTERNALERROR>   File "/Users/.../tests/conftest.py", line 14, in <lambda>
INTERNALERROR>     items.sort(key=lambda x: 2 if x.get_marker('slow') else 1)
INTERNALERROR> AttributeError: 'Function' object has no attribute 'get_marker'

======================================================================= no tests ran in 0.30 seconds ================================================
16
Messa

Dernière documentation suggère d'utiliser élément.iter_markers

https://docs.pytest.org/en/latest/example/markers.html#reading-markers-qui-wee-set-de-de-from-multiplaces

# content of conftest.py
import sys


def pytest_runtest_setup(item):
    for mark in item.iter_markers(name="glob"):
        print("glob args={} kwargs={}".format(mark.args, mark.kwargs))
        sys.stdout.flush()
0
Sameer Girolkar