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' #4608

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

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

mbarkhau opened this issue Jan 6, 2019 · 21 comments

Comments

@mbarkhau
Copy link

mbarkhau commented Jan 6, 2019

============= test session starts ===========
platform linux -- Python 3.6.6, pytest-4.0.2, py-1.7.0, pluggy-0.8.0 -- 
plugins: monkeytype-1.0.1, cov-2.6.0

Tests work if I pin pytest to this version. Updating to 4.1.0 breaks with this error:

platform linux -- Python 3.6.6, pytest-4.1.0, py-1.7.0, pluggy-0.8.0 -- 
plugins: monkeytype-1.0.1, cov-2.6.0

...

self = <pytest_cov.plugin.CovPlugin object at 0x7f13154272b0>, item = <Function test_part_compilation[PP]>

    @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'

/home/mbarkhau/miniconda3/envs/pycalver_py36/lib/python3.6/site-packages/pytest_cov/plugin.py:289: AttributeError

I can reproduce the error and provide more information in case it isn't immediately clear what the issue is.

@blueyed
Copy link
Contributor

blueyed commented Jan 6, 2019

Duplicate of pytest-dev/pytest-cov#252.

@blueyed blueyed closed this as completed Jan 6, 2019
@mbarkhau
Copy link
Author

mbarkhau commented Jan 6, 2019

Hah! Literally the same title. Literally! Sorry about that.

@blueyed
Copy link
Contributor

blueyed commented Jan 6, 2019

At least in another repo.. ;)

@s2t2
Copy link

s2t2 commented Mar 6, 2019

Hi, I'm running into this issue with pytest version 4.3.0 (Python version 3.7.0). Please advise!

@s2t2
Copy link

s2t2 commented Mar 6, 2019

Is there a specific version that is considered stable?

@s2t2
Copy link

s2t2 commented Mar 6, 2019

UPDATE: I was able to bypass the error by reverting to pytest 3.x:

pip install pytest==3.10.1

NOTE: I'm using anaconda.

@nicoddemus
Copy link
Member

@s2t2 that function no longer exists in pytest 4, you can use .get_closest_marker instead.

@s2t2
Copy link

s2t2 commented Mar 6, 2019

Thanks @nicoddemus - I wasn't trying to use that function, nor was I attempting to invoke it, but rather just trying to run a simple test and getting errors.

@s2t2
Copy link

s2t2 commented Mar 6, 2019

Just a simple invocation of pytest using the example function and test provided in the pytest documentation. For some reason I saw the error in question.

@nicoddemus
Copy link
Member

Can you point to the docs you saw? We might have something outdated.

@blueyed
Copy link
Contributor

blueyed commented Mar 7, 2019

@s2t2
It might also have been some plugin you were using.
Indeed:

pytest_cov.plugin.CovPlugin

@blueyed
Copy link
Contributor

blueyed commented Mar 7, 2019

cov-2.6.1 should fix this.

@s2t2
Copy link

s2t2 commented Mar 8, 2019

Was originally following installation instructions here: https://docs.pytest.org/en/latest/getting-started.html

I think it might be an anaconda thing. Here is some more info: s2t2/testing-123-py#2

@blueyed
Copy link
Contributor

blueyed commented Mar 8, 2019

@s2t2
In s2t2/testing-123-py#2 it is triggered by another plugin..

@Hawk32604088
Copy link

if invoke pytest, the name of func you defined can't be with prefix "test".

shuttle1987 added a commit to persephone-tools/persephone that referenced this issue Jun 27, 2019
yagmurdalman added a commit to yagmurdalman/sposm that referenced this issue Nov 18, 2019
Spesific version is used because of the error I got.

pytest-dev/pytest#4608
@mirhmousavi
Copy link

mirhmousavi commented Nov 23, 2019

rename function get_marker to get_closest_marker in /usr/local/lib/python3.6/site-packages/pytest_cov/plugin.py

solved for me

@RonnyPfannschmidt
Copy link
Member

@mirhmousavi that solution is a last stop measure - more recent versions of pytest-cov already have this done correctly - updating is preferred to editing random installed files

@mirhmousavi
Copy link

@RonnyPfannschmidt I had installed pytest-cov from a local repo and it installed v2.6.0
I upgraded and everything's OK
Thanks

@RonnyPfannschmidt
Copy link
Member

Thanks for the follow up and happy programming

@arvindpdmn
Copy link

arvindpdmn commented May 6, 2020

I'm using pytest-cov 2.8.1 and still get the error.

Edit:
Updating pytest-remotedata==0.3.0 to pytest-remotedata==0.3.2 solved the problem for me. Anaconda dist on Windows 10 but I updated using pip, not conda

@nicoddemus
Copy link
Member

Thanks @arvindpdmn for coming back to post the solution. 👍

tallamjr added a commit to LSSTDESC/snmachine that referenced this issue May 14, 2020
Errors:

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

REF:

    - https://stackoverflow.com/questions/54254337/pytest-attributeerror-function-object-has-no-attribute-get-marker
    - pytest-dev/pytest#4608
    - pytest-dev/pytest-cov#252

	modified:   environment.yml
tallamjr added a commit to LSSTDESC/snmachine that referenced this issue May 14, 2020
Errors:

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

REF:

    - https://stackoverflow.com/questions/54254337/pytest-attributeerror-function-object-has-no-attribute-get-marker
    - pytest-dev/pytest#4608
    - pytest-dev/pytest-cov#252

	modified:   environment.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants