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.

magic handling of mock.patch() is confusing and not generic enough.

See original GitHub issue

Okay, so I’m raising this as a result of:

https://github.com/Simplistix/testfixtures/issues/65

testfixtures’ log_capture() (and a couple of other decorators it offers) use the same pattern as mock.patch as implemented here:

https://github.com/Simplistix/testfixtures/blob/efc8082211e1c462aea23307d4ff4788e582bdce/testfixtures/utils.py#L24

However, I see that mock.patch only works because of the magical handling here:

https://github.com/pytest-dev/pytest/blob/46e30435ebad1796e54d99572d43a5b6a1961a19/_pytest/compat.py#L74

This means that end users and library developers are confused when one works and not the other does not. Not sure I have any good suggestions, just wanted to vent over the hours I’ve wasted on this…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:25 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
cjw296commented, Jan 18, 2018

I think from a pytest perspective, this can be closed.

0reactions
nicoddemuscommented, Jan 18, 2018

Is this still an issue? It is marked as “Need information”, what information is missing?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why python mock patch doesn't work? - Stack Overflow
When I run python test_spike.py , the first test case would pass, but the second would fail. and I switch to use nosetests...
Read more >
unittest.mock — mock object library — Python 3.11.1 ...
The Mock classes have support for mocking magic methods. See magic methods for the full details. The mock classes and the patch() decorators...
Read more >
pytest should use the inspect.signature algorithm to determine ...
pytest 3.0.6 on python 3.6, Arch Linux (distro packages). ... magic handling of mock.patch() is confusing and not generic enough. #2828.
Read more >
Using Mocks to Test External Dependencies or Reduce ...
We mock out the send_mail function again using the patch decorator, but this time we're interested in the body argument from the call...
Read more >
Why your mock doesn't work - Ned Batchelder
patch function in a with statement. It makes a mock object, assigns it to the name given, and then restores the original value...
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