The correct approach would be to mock all the code with side effects (I will assume that you don't want to) with empty mocks.
This file is test_module my_module:
def do_something_and_destroy_world(): destroy_world() return None
Sample test file:
import mock import unittest import my_module class MyTest(unittest.TestCase): def testSomethingUgly(self): with mock.patch('my_module.destroy_world', return_value=None): result = do_something_and_destroy_world() self.assertIsNone(result)
When the tests are executed, the statement will be correct, and destroy_world will not be called - instead, it will be replaced by an empty layout with a fixed return value.
source share