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

KeyError: '__wrapped__' with from xxx import yyy #5080

Closed
ZaydH opened this issue Apr 10, 2019 · 6 comments

Comments

Projects
None yet
3 participants
@ZaydH
Copy link

commented Apr 10, 2019

Checklist

  • Include a detailed description of the bug or suggestion
  • pip list of the virtual environment you are using
  • pytest and operating system versions
  • Minimal example if possible

Description

I implemented tox and pytest for automated testing. When I run the MWE, I get a KeyError: '__wrapped__' when I perform a from xxx import yyy.

In the example I included, I do not get the KeyError if I comment out the line:

...
from sty import fg
...

Pip List

No virtual environment used.

Version Info

Python: 3.6.5 & 3.7.1
PyTest: 4.4.0
OS: MacOS Mojave 10.14.4

MWE

I created a very simple repo. If I clone the repo and call either tox or pytest in the root directory, I get the error.

Example Error Message

➜  pytest_bug git:(master) ✗ tox
GLOB sdist-make: /Users/zayd/repos/pytest_bug/setup.py
py36 recreate: /Users/zayd/repos/pytest_bug/.tox/py36
py36 installdeps: pytest, sty
py36 inst: /Users/zayd/repos/pytest_bug/.tox/.tmp/package/1/stratego-0.0.0.zip
py36 installed: atomicwrites==1.3.0,attrs==19.1.0,more-itertools==7.0.0,pluggy==0.9.0,py==1.8.0,pytest==4.4.0,six==1.12.0,stratego==0.0.0,sty==1.0.0b9
py36 run-test-pre: PYTHONHASHSEED='591797669'
py36 run-test: commands[0] | pytest
============================================================================================================== test session starts ==============================================================================================================
platform darwin -- Python 3.6.5, pytest-4.4.0, py-1.8.0, pluggy-0.9.0
cachedir: .tox/py36/.pytest_cache
rootdir: /Users/zayd/repos/pytest_bug, inifile: tox.ini
collected 0 items / 1 errors                                                                                                                                                                                                                    

==================================================================================================================== ERRORS =====================================================================================================================
_____________________________________________________________________________________________________ ERROR collecting stratego/printer.py ______________________________________________________________________________________________________
../../.pyenv/versions/3.6.5/Python.framework/Versions/3.6/lib/python3.6/doctest.py:933: in find
    self._find(tests, obj, name, module, source_lines, globs, {})
.tox/py36/lib/python3.6/site-packages/_pytest/doctest.py:406: in _find
    self, tests, obj, name, module, source_lines, globs, seen
../../.pyenv/versions/3.6.5/Python.framework/Versions/3.6/lib/python3.6/doctest.py:992: in _find
    if ((inspect.isroutine(inspect.unwrap(val))
.tox/py36/lib/python3.6/site-packages/_pytest/doctest.py:377: in _mock_aware_unwrap
    return real_unwrap(obj, stop=_is_mocked)
../../.pyenv/versions/3.6.5/Python.framework/Versions/3.6/lib/python3.6/inspect.py:512: in unwrap
    while _is_wrapper(func):
../../.pyenv/versions/3.6.5/Python.framework/Versions/3.6/lib/python3.6/inspect.py:506: in _is_wrapper
    return hasattr(f, '__wrapped__') and not stop(f)
E   KeyError: '__wrapped__'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================ 1 error in 0.25 seconds ============================================================================================================
ERROR: InvocationError for command /Users/zayd/repos/pytest_bug/.tox/py36/bin/pytest (exited with code 2)
____________________________________________________________________________________________________________________ summary ____________________________________________________________________________________________________________________
ERROR:   py36: commands failed

My apologies if this bug is obvious or I am doing something wrong.

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Apr 10, 2019

https://github.com/feluxe/sty/blob/master/sty/primitive.py#L62-L66 is incorrect

the problem is a bug in sty

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Apr 10, 2019

@ZaydH

This comment has been minimized.

Copy link
Author

commented Apr 10, 2019

Thank you. Since I was able to import without from it did not occur to me this could be an sty problem. It feels like this is good to close since nothing can be done on your side. Do you agree?

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Apr 10, 2019

pytest could error better to help identifying the object or even ignore "broken" objects in the given context and only issuing a warning to take note of the issue

@Zac-HD

This comment has been minimized.

Copy link
Member

commented Apr 12, 2019

In this case it's actually an error from the standard library, caused by an invalid third-party library. This is impossible to detect in general, and very hard even in "normal" cases, so IMO trying to issue a warning is impractical.

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Apr 12, 2019

the mock aware unwrap is code in pytest that monkeypatches the stdlib

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.