Testing on Windows: TemporaryDirectory can't be cleaned
klieret opened this issue · comments
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?
Yes, locally I also get a permission error.
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
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
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.
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?)
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
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.
oh, nice :) Thanks!
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