pytest-cov: AttributeError: 'Function' object has no attribute 'get_marker'

I just started getting the following error with pytest-cov v2.6.0, pytest v4.1.0 on Python 3.4.6, PyPy, and PyPy3

self = <pytest_cov.plugin.CovPlugin object at 0x110f365c0>, item = <Function test_x>

    @compat.hookwrapper
    def pytest_runtest_call(self, item):
>       if (item.get_marker('no_cover')
                or 'no_cover' in getattr(item, 'fixturenames', ())):
E               AttributeError: 'Function' object has no attribute 'get_marker'

../.pyenv/versions/3.4.9/envs/venv/lib/python3.4/site-packages/pytest_cov/plugin.py:289: AttributeError

How to replicate

  • Create a virtualenv with Python 3.4.9

  • pip install pytest==4.1.0 pytest-cov==2.6.0

  • Create something.py with the following contents:

def test_x():
    assert True
  • Run pytest --cov=something something.py

Pytest output

========================================================== test session starts ===========================================================
platform darwin -- Python 3.4.9, pytest-4.1.0, py-1.7.0, pluggy-0.8.0 -- /Users/ross/.pyenv/versions/3.4.9/envs/venv/bin/python
cachedir: .pytest_cache
rootdir: /Users/ross/temp, inifile:
plugins: cov-2.6.0
collected 1 item

something.py::test_x FAILED                                                                                                        [100%]

================================================================ FAILURES ================================================================
_________________________________________________________________ test_x _________________________________________________________________

self = <pytest_cov.plugin.CovPlugin object at 0x110f365c0>, item = <Function test_x>

    @compat.hookwrapper
    def pytest_runtest_call(self, item):
>       if (item.get_marker('no_cover')
                or 'no_cover' in getattr(item, 'fixturenames', ())):
E               AttributeError: 'Function' object has no attribute 'get_marker'

../.pyenv/versions/3.4.9/envs/venv/lib/python3.4/site-packages/pytest_cov/plugin.py:289: AttributeError

---------- coverage: platform darwin, python 3.4.9-final-0 -----------
Name           Stmts   Miss  Cover
----------------------------------
something.py       2      1    50%

======================================================== 1 failed in 0.07 seconds ========================================================

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 19
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

conda install pytest; pip install pytest-remotedata>=0.3.1 and things start working.

pytest-cov 2.6.1 is released.

pip install "pytest-remotedata>=0.3.1" unless you want to redirect to a file (in fish at least). But otherwise, great fix Baran.

@nicoddemus It’s also fixed in pytest-remotedata 0.3.1 which @prashant-bansod has installed - based on the stacktrace above, the error @prashant-bansod is seeing is in their testsuite (or whatever topology.pytest.plugin is).

We are seeing the same error with latest version of pytest.

OK: pytest==4.02 with pytest-cov-2.6.0 FAILS: pytest==4.1.0 with pytest-cov-2.6.0