Skip to content

Instantly share code, notes, and snippets.

@padawin
Last active January 18, 2018 16:03
Show Gist options
  • Save padawin/595736286a49fed259de310fb39401c1 to your computer and use it in GitHub Desktop.
Save padawin/595736286a49fed259de310fb39401c1 to your computer and use it in GitHub Desktop.

failing mock with function imported

def func1():
return "1"
def func2():
return "2"
from unittest.mock import patch
import toTest
import module1
import module2
@patch.object(module1, 'func1')
@patch.object(module2, 'func2')
def test_myfuncs(mock2, mock1):
mock1.return_value = "Return mock 1"
mock2.return_value = "Return mock 2"
res = toTest.functionToTest()
assert res == ("Return mock 1", "Return mock 2")
import module1
from module2 import func2
def functionToTest():
return module1.func1(), func2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment