question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

__module__ is not set on spied functions

See original GitHub issue

Python 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nicoddemuscommented, May 7, 2019

Yes I believe so. Could you please open a bug report on CPython? Thanks!

Closing this for now then.

0reactions
nicoddemuscommented, May 7, 2019

Great, thanks for the follow up!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found