Skip to content

Instantly share code, notes, and snippets.

@orsenthil
Created September 12, 2017 20:40
Show Gist options
  • Save orsenthil/ae7c9840ca2b4ee7331f2f7fb39eaae1 to your computer and use it in GitHub Desktop.
Save orsenthil/ae7c9840ca2b4ee7331f2f7fb39eaae1 to your computer and use it in GitHub Desktop.
Using Mock
class Production:
def call_one(self, arg1, arg2):
return arg1 + arg2
def call_two(self, arg1, arg2, arg3):
return self.call_one(str(arg1), str(arg2) + str(arg3))
from unittest import mock
import unittest
from production import Production
class TestModule(unittest.TestCase):
@mock.patch("production.Production.call_one")
def test_case(self, mock_call_one):
expected = "something"
mock_call_one.return_value = expected
prod = Production()
response = prod.call_two(1, 2, 3)
self.assertEqual(response, expected)
@orsenthil
Copy link
Author


Ran 1 test in 0.001s

OK
Launching unittests with arguments python -m unittest testing.TestModule in /Users/senthil/workspace/pymockexample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment