Skip to content

Instantly share code, notes, and snippets.

@lattejed
Created October 4, 2010 18:28
Show Gist options
  • Save lattejed/610197 to your computer and use it in GitHub Desktop.
Save lattejed/610197 to your computer and use it in GitHub Desktop.
# Watch the file given at the command line
if __name__ == '__main__':
old_mtime = 0
while True:
if len(sys.argv) == 1:
print 'Usage: python this_file.py your_module.py'
sys.exit()
else:
test = sys.argv[1].split('.')[0]
# Load here so we can use imp.reload later
test_mod = __import__(test)
# TODO: update this to handle Win
mtime = os.stat(sys.argv[1]).st_mtime
if mtime != old_mtime:
try:
old_mtime = mtime
# unittest loads as module is already loaded
# so needs to be manually reloaded each time
imp.reload(test_mod)
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromName(test))
unittest.TextTestRunner().run(suite)
# Show any exceptions
except Exception as e:
print str(type(e)), e
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment