Example #1
0
 def test_patch_decorators(self, mock_my_method):
     """
     Patch Decorators
     """
     mock_my_method.return_value = True
     assert Customer._some_data == "hehehe"  # the attributed is patched
     Customer.init()  # calling real class method resets attribute to its real state
     assert Customer._some_data == [1, 2, 3]  # And for real Customer class it should be [1,2,3]
Example #2
0
        """
        Patch Decorators
        """
        mock_my_method.return_value = True
        assert Customer._some_data == "hehehe"  # the attributed is patched
        Customer.init()  # calling real class method resets attribute to its real state
        assert Customer._some_data == [1, 2, 3]  # And for real Customer class it should be [1,2,3]

    @patch("samples1.my_module_attribute", "FOO")
    def test_patch_decorators(self):
        """
        Patch Decorators
        """
        # the attribute is patched, the patch value will disapear on exit from this method
        from samples1 import my_module_attribute

        assert my_module_attribute == "FOO"


Customer.init()
original = Customer._some_data


@patch.object(Customer, "_some_data", sentinel._some_data)
def test():
    assert Customer._some_data == sentinel._some_data


test()
assert Customer._some_data == original