'python unittest patch works with 3.8 but not with python 3.7
I have a class in module.py
class Class():
def foo(self): return "not bar"
I am patching an object in my unittest like this:
from unittest.mock import patch
@patch("module.Class")
def test_test(mock_class):
mock_class().foo.return_value = "bar"
I am expecting that when foo
is called on an instance of module.Class
that it should not run the actual function, but just return "bar"
.
With python 3.8.2 this work for me just fine, but with 3.7.9 the patch does not seem to work. Any ideas what the problem might be?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|