Beispiel #1
0
class TestPatchClass(TestCase):
    def setUp(self):
        self.obj = PatchClass()

    @patch('class_under_test.PatchClass.m_2')
    def test_patch_as_decorator(self, m_2_mock):
        self.obj.m_1()
        m_2_mock.assert_called()
class TestPatchClass(TestCase):
    def setUp(self):
        self.obj = PatchClass()

    def test_patch_as_context_manager_with_incorrect_import(self):
        with patch('PatchClass.m_2') as cm:
            self.obj.m_1()
            cm.assert_called()

    def test_patch_as_context_manager_with_correct_assert(self):
        with patch('class_under_test.PatchClass.m_2') as cm:
            self.obj.m_1()
            cm.assert_called()

    def test_patch_as_context_manager_with_incorrect_assert(self):
        with patch('class_under_test.PatchClass.m_2') as cm:
            self.obj.m_1()
            cm.assert_not_called()