This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients barry, brett.cannon, ncoghlan, neologix, pitrou
Date 2011-12-21.12:41:17
SpamBayes Score 9.821638e-07
Marked as misclassified No
Message-id <1324471278.91.0.028900462423.issue13645@psf.upfronthosting.co.za>
In-reply-to
Content
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")
History
Date User Action Args
2011-12-21 12:41:19pitrousetrecipients: + pitrou, barry, brett.cannon, ncoghlan, neologix
2011-12-21 12:41:18pitrousetmessageid: <1324471278.91.0.028900462423.issue13645@psf.upfronthosting.co.za>
2011-12-21 12:41:18pitroulinkissue13645 messages
2011-12-21 12:41:17pitroucreate