import os import stat import time import unittest import string filesToWatch = ('dbi.py', 'dbiq.py', 'test_dbi.py', 'test_dbiq.py') accessTime = {} testDrivers = ('test_dbi.py', 'test_dbiq.py') def AnyFilesChanged(): changed = False for fileName in filesToWatch: try: st = os.stat(fileName) except os.error: continue if fileName not in accessTime or st[stat.ST_MTIME] > accessTime[fileName]: accessTime[fileName] = st[stat.ST_MTIME] changed = True print '[%s changed at %s]' % (fileName, st[stat.ST_MTIME]) return changed def RunTests(driver): program = 'python' args = (driver,) print '[', driver, ']' # find executable for path in string.split(os.environ["PATH"], os.pathsep): file = os.path.join(path, program) try: return os.spawnv(os.P_WAIT, file, (file,) + args) except os.error: pass raise os.error, "cannot find executable" while(1): if AnyFilesChanged(): for driver in testDrivers: RunTests(driver) time.sleep(0.10)