def test_child_command_rolls_back_self_on_exception(self): # Assemble command chain with mocked __do__ functions # Initial command triggered will throw exception c1 = Command() c2 = Command(previous=c1) c2.__do__ = Mock(side_effect=Exception('Oh No!')) c2.__undo__ = Mock() # Action c1.run() # Assert command 2 was rolled back c2.__undo__.assert_called_once()