Skip to content
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

Remove use of allow_cleanup_failure in test_backends.py #1668

Open
shoyer opened this issue Oct 28, 2017 · 6 comments
Open

Remove use of allow_cleanup_failure in test_backends.py #1668

shoyer opened this issue Oct 28, 2017 · 6 comments

Comments

@shoyer
Copy link
Member

shoyer commented Oct 28, 2017

This exists for the benefit of Windows, on which trying to delete an open file results in an error. But really, it would be nice to have a test suite that doesn't leave any temporary files hanging around.

The main culprit is tests like this, where opening a file triggers an error:

with raises_regex(TypeError, 'pip install netcdf4'):
    open_dataset(tmp_file, engine='scipy')

The way to fix this is to use mocking of some sort, to intercept calls to backend file objects and close them afterwards.

@stale
Copy link

stale bot commented Sep 28, 2019

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

@stale stale bot added the stale label Sep 28, 2019
@max-sixty
Copy link
Collaborator

Maybe I don't understand the whole problem—can we just use a temp dir for these?

@stale stale bot removed the stale label Sep 28, 2019
@shoyer
Copy link
Member Author

shoyer commented Sep 28, 2019

We currently try to explicitly close any temp files we created at the end of each test. Are you suggesting that we should leave that clean-up to the operating system?

@max-sixty
Copy link
Collaborator

We currently try to explicitly close any temp files we created at the end of each test. Are you suggesting that we should leave that clean-up to the operating system?

IIUC (and my understand isn't advanced here!), python will close and delete temp files & directories once they leave scope:

From
https://docs.python.org/3/library/tempfile.html#examples


# create a temporary file using a context manager
>>> with tempfile.TemporaryFile() as fp:
...     fp.write(b'Hello world!')
...     fp.seek(0)
...     fp.read()
b'Hello world!'
>>>
# file is now closed and removed

https://docs.python.org/3/library/tempfile.html#tempfile.TemporaryDirectory

Or is it that we want to test that they're closed?

@shoyer
Copy link
Member Author

shoyer commented Sep 29, 2019

It might more informative to try removing and this option and to see what fails when you run CI :).

Our current temp file decorator will try to delete files as soon as we exit the scope, but if the file wasn't closed first this results in an exception on Windows. (This can happen because we only generate file names and let lower level library like netCDF open/close the files -- there are usually no Python level file objects, so we can't use tempfile.TemporaryFile.)

@max-sixty
Copy link
Collaborator

OK, yes I see now. I didn't know about that windows behavior. There's a broader CPython issue about it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants