import os

def makeModule(modname, text):
  f = open("%s.py" % modname, 'w')
  f.write(text)
  f.close()

## Module 'a' defines a value
makeModule('a', 'value = 1\n')

## Module 'b' imports value from 'a'
makeModule('b', 'from a import value\n')

import a,b
assert b.value == 1

## Change the value in 'a'
makeModule('a', 'value = 2\n')

## Reload to get the changes
#  First have to delete the 'pyc' files, or the identical
#  timestamp will cause Python to not bother re-compiling
try: os.unlink('a.pyc')
except: pass
try: os.unlink('b.pyc')
except: pass

reload(b)
reload(a)

assert a.value == 2
# The following assertion fails due to the reloading order
assert b.value == 2, "b.value is actually %i" % b.value