Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Function' object has no attribute 'get_marker' #252

Closed
rossmacarthur opened this issue Jan 6, 2019 · 21 comments

Comments

Projects
None yet
@rossmacarthur
Copy link

commented Jan 6, 2019

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 ========================================================
@rossmacarthur

This comment has been minimized.

Copy link
Author

commented Jan 6, 2019

Possibly because of this pytest-dev/pytest#4564?

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jan 6, 2019

this should have been triggering errors since pytest==4.0.0

@bbernays

This comment has been minimized.

Copy link

commented Jan 6, 2019

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

slwatkins added a commit to ucbpylegroup/QETpy that referenced this issue Jan 6, 2019

Specify pytest version to 4.0.2
version 4.1.0 was updated on PyPI on Jan 6, 2019, which broke pytest-cov pytest-dev/pytest-cov#252

ticosax added a commit to ticosax/django-fsm-log that referenced this issue Jan 6, 2019

@blueyed

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2019

Fixed in #253.

@blueyed blueyed closed this Jan 6, 2019

@blueyed

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2019

pytest-cov is not tested against current/newer pytest versions.
It is being worked on in #240.

@nicoddemus

This comment has been minimized.

Copy link
Member

commented Jan 6, 2019

this should have been triggering errors since pytest==4.0.0

Indeed, that was the idea... can anyone explain why was that not the case? Perhaps migrating directly from 3.X to 4.1 caused this?

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jan 6, 2019

@nicoddemus i just noted the detail issue - remember get_marker function it was only documented deprecated, but the actual warnings got triggered by usage of the return value

https://github.com/pytest-dev/pytest/pull/4564/files#diff-c4fc03c3a0d271a27a48958fb69a6b6f basically

c00kiemon5ter referenced this issue in IdentityPython/pysaml2 Jan 6, 2019

Do not hardcode the warning filter
The application should control whether warnings should be visible or not. By
hardcoding the simplefilter we turn on warnings' visibility for all modules
that follow. Removing this allows the application code to decide if warnings
should be shown.

To enable warnings through the command line pass -Wd to the python interpreter.

Quoting the python warnings module documentation[0]:
> You can do this from the command-line by passing -Wd to the interpreter (this
> is shorthand for -W default). This enables default handling for all warnings,
> including those that are ignored by default. To change what action is taken
> for encountered warnings you simply change what argument is passed to -W,
> e.g. -W error. See the -W flag for more details on what is possible.

  [0]: https://docs.python.org/2/library/warnings.html#updating-code-for-new-versions-of-python

Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
@ionelmc

This comment has been minimized.

Copy link
Member

commented Jan 7, 2019

pytest-cov 2.6.1 is released.

@AlmogCohen

This comment has been minimized.

Copy link

commented Jan 17, 2019

Oops! Seems like I should blame another repo for not catching up yet like you did ;) I'll post there, maybe with a proper PR. Thanks!

@AlmogCohen

This comment has been minimized.

Copy link

commented Jan 17, 2019

Could you please link to the PR where you fixed this issue so I can fix it in another repo depending on pytest?

@rossmacarthur

This comment has been minimized.

Copy link
Author

commented Jan 17, 2019

@AlmogCohen I do believe it was fixed in #253

@The-Compiler

This comment has been minimized.

Copy link
Member

commented Jan 17, 2019

@AlmogCohen Note there is getsentry/pytest-responses#7 already 😉

@rawrgulmuffins

This comment has been minimized.

Copy link

commented Feb 11, 2019

Currently seeing this with pytest-cov 2.6.1

$ pip list | grep pytest
pytest                             4.2.0
pytest-arraydiff                   0.2
pytest-astropy                     0.3.0
pytest-cov                         2.6.1
pytest-doctestplus                 0.1.3
pytest-openfiles                   0.3.0
pytest-remotedata                  0.2.1
$ python -m pytest
=============================== test session starts ================================
platform darwin -- Python 3.6.5, pytest-4.2.0, py-1.5.3, pluggy-0.8.1
rootdir: /Users/alexl/git/example, inifile: setup.cfg
plugins: remotedata-0.2.1, openfiles-0.3.0, doctestplus-0.1.3, cov-2.6.1, arraydiff-0.2
collected 1 item

tests/test_example.py E                                                      [100%]

====================================== ERRORS ======================================
__________________ ERROR at setup of test_command_line_interface ___________________

item = <Function test_command_line_interface>

    def pytest_runtest_setup(item):

>       remote_data = item.get_marker('remote_data')
E       AttributeError: 'Function' object has no attribute 'get_marker'

/usr/local/anaconda3/lib/python3.6/site-packages/pytest_remotedata/plugin.py:59: AttributeError
============================= 1 error in 0.12 seconds ==============================
@rossmacarthur

This comment has been minimized.

Copy link
Author

commented Feb 11, 2019

@rawrgulmuffins This looks like a bug in pytest-remotedata

@rawrgulmuffins

This comment has been minimized.

Copy link

commented Feb 11, 2019

@rossmacarthur I'll go make an issue that links to this one then.

@BaranOrnarli

This comment has been minimized.

Copy link

commented Feb 13, 2019

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

@endrebak

This comment has been minimized.

Copy link

commented Apr 9, 2019

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

wtgee added a commit to wtgee/panoptes-utils that referenced this issue Apr 11, 2019

Upping plugin version.
Seeing this on test scripts when run from latest docker image:

pytest-dev/pytest-cov#252
@prashant-bansod

This comment has been minimized.

Copy link

commented Jul 15, 2019

======================================= ERRORS =======================================
_________________________ ERROR at setup of test_constructor _________________________

item = <Function test_constructor>

    @hookimpl(tryfirst=True)
    def pytest_runtest_setup(item):
        """
        pytest hook to setup test before run.
        """
>       test_id_marker = item.get_marker('test_id')
E       AttributeError: 'Function' object has no attribute 'get_marker'

/anaconda3/envs/vaak/lib/python3.6/site-packages/topology/pytest/plugin.py:311: AttributeError
============================== 1 error in 0.04 seconds ===============================

$ pip list | grep pytest

pytest              5.0.1      
pytest-remotedata   0.3.1      

Is there any fix for this? Thanks.

@The-Compiler

This comment has been minimized.

Copy link
Member

commented Jul 15, 2019

@prashant-bansod This seems completely unrelated to pytest-cov or pytest-remotedata. You'll need to ask the author of topology/pytest/plugin.py to update their code.

@nicoddemus

This comment has been minimized.

@The-Compiler

This comment has been minimized.

Copy link
Member

commented Jul 15, 2019

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.