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

Testing on Windows: TemporaryDirectory can't be cleaned #59

Closed
klieret opened this issue Dec 5, 2020 · 10 comments
Closed

Testing on Windows: TemporaryDirectory can't be cleaned #59

klieret opened this issue Dec 5, 2020 · 10 comments
Labels
bug Something isn't working

Comments

@klieret
Copy link
Owner

klieret commented Dec 5, 2020

If you run pytest locally on Windows, there are weird PermissionErrors: Some other process seems to be still running that is using a file from the TemporaryDirectory, hence it can't be removed.

@exc4l do you see this issue when running locally under Windows as well?

@klieret klieret added the bug Something isn't working label Dec 5, 2020
@klieret
Copy link
Owner Author

klieret commented Dec 5, 2020

example

@exc4l
Copy link
Contributor

exc4l commented Dec 5, 2020

Yes, locally I also get a permission error.

@exc4l
Copy link
Contributor

exc4l commented Dec 5, 2020

col.notes.add_tag seems to be the culprit. I only focused on one of the tests. Might be that the dataframe manipulation causes somekind of os.cwd to be in the directory which could result in this error.

And tempfile causing permissions errors under windows does also seem to be quite the common report.
https://bugs.python.org/issue35144

@exc4l
Copy link
Contributor

exc4l commented Dec 6, 2020

Btw since you are already using pytest. Any reason to not use the tmp_path provided by pytest?
https://docs.pytest.org/en/stable/tmpdir.html#base-temporary-directory

@klieret
Copy link
Owner Author

klieret commented Dec 6, 2020

Btw since you are already using pytest. Any reason to not use the tmp_path provided by pytest?
https://docs.pytest.org/en/stable/tmpdir.html#base-temporary-directory

Yeah, back then I was still mostly using the unittest framework. Would do a lot of things differently. But perhaps it's worth to try out if using the pytest fixtures handles this better.

@klieret
Copy link
Owner Author

klieret commented Dec 6, 2020

col.notes.add_tag seems to be the culprit.

Ah, I don't think so, because that also happens if you simply read and write the same collection. I think this really is a more fundamental issue about reading and writing files (and perhaps not closing them at some point?)

@klieret
Copy link
Owner Author

klieret commented Dec 6, 2020

Switching to pytest solved things! Not sure if it was a change on the way, or just your recommendation of tmp_path, but it's working now :D

@klieret klieret closed this as completed Dec 6, 2020
@exc4l
Copy link
Contributor

exc4l commented Dec 6, 2020

pytest provides tmpdir and tmp_path.
tmp_path is already a pathlib object.
i.e.

def test_tmp(tmp_path):
    (tmp_path/ "sub").mkdir()

works and you would save the casting.

@klieret

@klieret
Copy link
Owner Author

klieret commented Dec 6, 2020

oh, nice :) Thanks!

@klieret
Copy link
Owner Author

klieret commented Dec 9, 2020

though I saw some issues with that in py3.5 that still require usage of str: pytest-dev/pytest#5017

But probably we can/should drop py3.5 support at some point soon anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants