__module__ is not set on spied functions
See original GitHub issuePython 3.7.2 pytest==3.10.1 pytest-mock==1.10.4
qwe.py
def asdasd():
pass
tests/test_asd.py
import qwe
def test_zxc(mocker):
spy_asdasd = mocker.spy(qwe, 'asdasd')
assert spy_asdasd.__module__ == 'qwe'
======================= FAILURES ========================
_______________________ test_zxc ________________________
mocker = <pytest_mock.MockFixture object at 0x7fcee95dc400>
def test_zxc(mocker):
spy_asdasd = mocker.spy(qwe, 'asdasd')
> assert spy_asdasd.__module__ == "qwe"
E AssertionError: assert None == 'qwe'
E + where None = <function asdasd at 0x7fcee95702f0>.__module__
tests/test_asd.py:7: AssertionError
==== 1 failed, 100 passed, 1 skipped in 0.10 seconds ====
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Spying on module functions in jest - Stack Overflow
I am writing tests with jest in which I want to spy on some lodash functions, that I import separately in the module...
Read more >jest cannot spy because it is not a function - You.com
Jest: Cannot spy the property because it is not a function; undefined given instead getting error while executing my test cases.
Read more >Jest Full and Partial Mock/Spy of CommonJS and ES6 Module ...
Spy on imports or mock part of a module by “referencing the module”. Warning: this will cause you to change the way you...
Read more >How to spy on your required modules | Toucan Toco
It will throw a TypeError: Attempted to wrap undefined property yeah as function . Solution with code modification. Note that I don't recommend...
Read more >ES6 Class Mocks - Jest
Again, this allows you to inject different behavior for testing, but does not provide a way to spy on calls. * Module factory...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes I believe so. Could you please open a bug report on CPython? Thanks!
Closing this for now then.
Great, thanks for the follow up!