[Zope-Checkins] CVS: Releases/Zope/utilities - testrunner.py:1.25
Guido van Rossum
guido@python.org
Tue, 7 May 2002 18:18:16 -0400
Update of /cvs-repository/Releases/Zope/utilities
In directory cvs.zope.org:/tmp/cvs-serv26204
Modified Files:
testrunner.py
Log Message:
Add "remove_stale_bytecode()". This removes .pyc and .pyo files that
don't have a corresponding .py file, to prevent tests that import
deleted modules from running using the stale bytecode files. This has
bitten enough people enough times that it's time it became a standard
part of every test suite runner. (Zope3 already has it.)
Somebody merge this into the Zope2 trunk please.
=== Releases/Zope/utilities/testrunner.py 1.24 => 1.25 ===
os.chdir(working_dir)
+def remove_stale_bytecode(arg, dirname, names):
+ names = map(os.path.normcase, names)
+ for name in names:
+ if name.endswith(".pyc") or name.endswith(".pyo"):
+ srcname = name[:-1]
+ if srcname not in names:
+ fullname = os.path.join(dirname, name)
+ print "Removing stale bytecode file", fullname
+ os.unlink(fullname)
def main(args):
@@ -304,6 +313,8 @@
sys.stderr = f
else:
err_exit(usage_msg)
+
+ os.path.walk(os.curdir, remove_stale_bytecode, None)
testrunner = TestRunner( os.getcwd()
, verbosity=verbosity