-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests using tempfile.NamedTemporaryFile fail on Windows 7 #111
Comments
changing e.g.:
to
works for Python >= 2.6.x (See also: http://bugs.python.org/issue6357). However in another project supporting Python 2.5.5 - Python 3.1.3 we use this utility function instead the original class for all tests using temporary files - but file handlers must be closed manually within the tests:
|
Hm. The entire point of the tempfile stuff there is to ensure that the OS is not in our way when doing things. However, it looks like Win7 is bound and determined to get in our way. Perhaps we should consider this a Python bug and not our bug. |
Windows does not allow processes other than the one used to create the NamedTemporaryFile to access the file when using The fix, in this case, is to set
|
Ugh. This is a trial bug, then? Joy... Will see if Twisted has a bug for this already. |
nope - its still a problem in Python tempfile.NamedTemporaryFile |
That doesn't seem like a Python bug since Python does not guarantee that temp files will be accessible across process boundaries, and in fact, it seems quite reasonable that this is the case. I'd rather blame trial, because of the way trial sandboxes things. Either way, I'm creating a "Windows" tag for these bugs, since they can't really be easily diagnosed on my end. I'm going to send a new patch to Twisted for http://twistedmatrix.com/trac/ticket/3931, which will hopefully fix this issue for Twisted 11.0 whenever it does come out. In the meantime, I don't want to patch those tests just for Windows, especially when the temp file usage is only in the tests and not in the actual code. (And also when NBT wouldn't even have this problem if it used FilePath instead of bare file handles.) |
You actually don't need trial to retrieve the same errors - just run: python bravo\tests\test_nbt.py. So imho its clearly Python related. Calling a explicit close() on the file handler of the temp file solves the issue for Python >= 2.6.x and I personally would forget about 2.5.x as this will be replaced sooner or later by more recent versions. |
It's an issue with Python, but it's not a bug. They clearly document this in the docs:
http://docs.python.org/library/tempfile.html#tempfile.NamedTemporaryFile |
by corrupting the notebook run function to work with windows. Inspired by https://stackoverflow.com/questions/46497842/passing-namedtemporaryfile-to-a-subprocess-on-windows and bravoserver/bravo#111 (comment)
- Fix from bravoserver/bravo#111 - This error is further documented on Stack Overflow (see ioos#261 for discussion)
- Fix from bravoserver/bravo#111 - This error is further documented on Stack Overflow (see ioos#261 for discussion)
Here is in output of unittests:
======================================================================
ERROR: test_empty_file (test_nbt.BugfixTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:/Workspace/bravo/bravo/tests\test_nbt.py", line 36, in test_empty_file
self.assertRaises(MalformedFileError, NBTFile, temp.name)
File "c:\Program Files\Python27\Lib\unittest\case.py", line 456, in assertRaises
callableObj(_args, *_kwargs)
File "d:\workspace\bravo\bravo\nbt.py", line 281, in init
self.file = GzipFile(filename, mode)
File "c:\Program Files\Python27\Lib\gzip.py", line 89, in init
fileobj = self.myfileobj = builtin.open(filename, mode or 'rb')
IOError: [Errno 13] Permission denied: 'c:\users\barsch\appdata\local\temp\tmp2eq3fb'
The text was updated successfully, but these errors were encountered: