Antoine Pitrou <[email protected]> added the comment:
The cause is that the import machinery checks the timestamp stored in the pyc
file to decide whether it must be refreshed. Depending on the system's
timestamp granularity, there can be false negatives: the py file was modified
twice with the same timestamp, but the pyc file isn't regenerated for the
second version of the py file. Adding a time.sleep(1) call to the failing test
case makes it pass.
Correct fix for 3.2's tests is the following. I don't know if the import
machinery can be improved not to exhibit any false negatives:
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -107,8 +107,9 @@ class ImportTests(unittest.TestCase):
open(fname, 'w').close()
os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
+ fn = imp.cache_from_source(fname)
+ unlink(fn)
__import__(TESTFN)
- fn = imp.cache_from_source(fname)
if not os.path.exists(fn):
self.fail("__import__ did not result in creation of "
"either a .pyc or .pyo file")
----------
nosy: +barry
stage: -> patch review
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue13645>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com