classification
Title: test_timestamp_overflow of test_importlib fails if PYTHONDONTWRITEBYTECODE is set
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: brett.cannon, inglesp, ned.deily, python-dev
Priority: normal Keywords: patch

Created on 2016-03-17 17:16 by inglesp, last changed 2016-03-17 21:59 by ned.deily. This issue is now closed.

Files
File name Uploaded Description Edit
issue26583.patch ned.deily, 2016-03-17 19:23 review
Messages (8)
msg261919 - (view) Author: Peter Inglesby (inglesp) * Date: 2016-03-17 17:16
I get the following test failure against changeset 100576 on OSX 10.9.5:

$ ./python.exe -m test test_import
[1/1] test_import
test test_import failed -- Traceback (most recent call last):
  File "/Users/peteringlesby/src/cpython/Lib/test/test_import/__init__.py", line 301, in test_timestamp_overflow
    os.stat(compiled)
FileNotFoundError: [Errno 2] No such file or directory: '__pycache__/@test_68937_tmp.cpython-36.pyc'

1 test failed:
    test_import
msg261922 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-03-17 17:41
Sorry, I am unable to reproduce this on either 10.9.5 or current 10.11.3 OS X systems.  Is there something unusual about the working directory you are running the tests from, like residing on an NFS or other networked file system?  Any special ./configure options?  Does the test always fail?
msg261927 - (view) Author: Peter Inglesby (inglesp) * Date: 2016-03-17 18:37
I can reproduce it reliably.

I ran ./configure with --with-pydebug.

I'm not using NFS, and I'm not aware of anything else unusual about my filesystem.

The fact that a timestamp overflows in the failing test is a red herring -- the following also fails, with os.stat raising FileNotFoundError:

    def test_without_timestamp_overflow(self):
        sys.path.insert(0, os.curdir)
        try:
            source = TESTFN + ".py"
            compiled = importlib.util.cache_from_source(source)
            with open(source, 'w') as f:
                pass
            __import__(TESTFN)
            os.stat(compiled)
        finally:
            del sys.path[0]
            remove_files(TESTFN)

I've verified that TESTFN does get imported by writing 'print("hello")' to the source file.
msg261929 - (view) Author: Peter Inglesby (inglesp) * Date: 2016-03-17 18:50
The problem is that I have PYTHONDONTWRITEBYTECODE set in my environment.

Should the setUp and tearDown methods ensure that PYTHONDONTWRITEBYTECODE is cleared and reset?
msg261930 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-03-17 19:23
Ah, setting PYTHONDONTWRITEBYTECODE explains it.  When running the tests via "make test", python is invoked with -E to avoid issues like that.  But here's a patch that skips test_timestamp_overflow if bytecode files cannot be written (Issue20796 documents a similar problem and workaround for test_import).
msg261931 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-03-17 19:50
LGTM, Ned.
msg261937 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-03-17 21:57
New changeset 915f158633f4 by Ned Deily in branch '3.5':
Issue #26583: Skip test_timestamp_overflow in test_import if bytecode
https://hg.python.org/cpython/rev/915f158633f4

New changeset e8cab14d8a47 by Ned Deily in branch 'default':
Issue #26583: merge from 3.5
https://hg.python.org/cpython/rev/e8cab14d8a47
msg261938 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-03-17 21:59
Pushed for release in 3.5.2 and 3.6.0.
History
Date User Action Args
2016-03-17 21:59:29ned.deilysetstatus: open -> closed
resolution: fixed
messages: + msg261938

stage: commit review -> resolved
2016-03-17 21:57:14python-devsetnosy: + python-dev
messages: + msg261937
2016-03-17 19:50:49brett.cannonsetassignee: larry -> ned.deily

nosy: - larry
2016-03-17 19:50:36brett.cannonsetnosy: + larry
messages: + msg261931

assignee: larry
stage: patch review -> commit review
2016-03-17 19:23:33ned.deilysetfiles: + issue26583.patch

components: - macOS
title: test_timestamp_overflow fails -> test_timestamp_overflow of test_importlib fails if PYTHONDONTWRITEBYTECODE is set
keywords: + patch
nosy: + brett.cannon, - ronaldoussoren
versions: + Python 3.5
messages: + msg261930
stage: patch review
2016-03-17 18:50:25inglespsetmessages: + msg261929
2016-03-17 18:37:42inglespsetmessages: + msg261927
2016-03-17 17:41:13ned.deilysetmessages: + msg261922
2016-03-17 17:23:38SilentGhostsetnosy: + ronaldoussoren, ned.deily
type: behavior
components: + macOS, Tests
2016-03-17 17:16:47inglespcreate