我有一个A类,它有两个方法:
def app1():
----some code-----
app2() # line 3
def app2():
----some code---
在为上面的类编写单元测试时,我在调用app1()方法 但我想从app1()方法中跳过调用方法app2()。
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.
答案 0 :(得分:1)
您正在谈论嘲笑
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()