When running a simple unittest it would sometimes be easier to be able to keep the tests inside the class. However, I don't know how to reload the current module, and so whenever that's needed I have to move the tests into a separate module. Is there a way around this?
module: foo
import unittest
class MyObject
...
class MockMyObject
...
class TestMock(unittest.TestCase):
def setUp(self):
MyObject = MockMyObject
mocked = MyObject()
def tearDown(self):
reload(foo) # what goes here?
def testFunction(self):
mocked.do_mocked_function()
if __name__ == "__main__":
unittest.main()
The way I've found to handle this is to import sys and reload(sys.modules[__name__]) in the tearDown method, but I'm wondering if there is a better method.