Reputation: 51
I have a class A, which has two methods :
def app1():
----some code-----
app2() # line 3
def app2():
----some code---
here while writing unit test for above class, I am calling app1() method but I want to skip the calling method app2() from app1() method.
class TestController(unittest.TestCase):
def setUp(self):
self.app = app1() # its failing here(at line 3), because there is some DB setting inside app2() which i want to skip.
Upvotes: 2
Views: 3264
Reputation: 1000
You are talking about mocking
from unittest import TestCase
from unittest.mock import patch
from apps import app1
class App1Tests(TestCase):
@patch('apps.app2')
def test_app1(self, app2):
app1()
app2.assert_called_once_with()
Upvotes: 3