Question: each unit test I'm running is writing python code out to a file, then importing it as a module. The problem is that the code changes but further import statements don't modify the module.

I think what I need is a way to ether force a reload on a module or clear the internal bytecode cache. Any ideas?

Thanks!

Answer: 
Write your code to differently-named modules. Writing new code into an existing file, and trying to import it again will not work well.

Alternatively, you can clobber `sys.modules`. For example:

```
class MyTestCase(unittest.TestCase):
    def setUp(self):
        # Record sys.modules here so we can restore it in tearDown.
        self.old_modules = dict(sys.modules)

    def tearDown(self):
        # Remove any new modules imported during the test run. This lets us
        # import the same source files for more than one test.
        for m in [m for m in sys.modules if m not in self.old_modules]:
            del sys.modules[m]

```
Ran into a similar situation.
Later on found that the white space indentation technique used matters.
Especially on windows platforms, ensure that a uniform technique is adapted 
throughout the module i.e., either use tab or spaces exclusively.