Commit efd87296 authored by Guido van Rossum's avatar Guido van Rossum

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.
parent 8215cdb5
...@@ -192,6 +192,15 @@ class TestRunner: ...@@ -192,6 +192,15 @@ class TestRunner:
sys.stderr.write( '*** Restoring directory to: %s\n' % working_dir ) sys.stderr.write( '*** Restoring directory to: %s\n' % working_dir )
os.chdir(working_dir) 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): def main(args):
...@@ -305,6 +314,8 @@ def main(args): ...@@ -305,6 +314,8 @@ def main(args):
else: else:
err_exit(usage_msg) err_exit(usage_msg)
os.path.walk(os.curdir, remove_stale_bytecode, None)
testrunner = TestRunner( os.getcwd() testrunner = TestRunner( os.getcwd()
, verbosity=verbosity , verbosity=verbosity
, mega_suite=mega_suite) , mega_suite=mega_suite)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment