`Transport` & `pytest`: garbage cannot be removed `[Errno 39]`
To reproduce
When running pytest test_all_plugins.py -s, despite all tests passing successful, a long tail of warning messages is printed:
..
warnings.warn(
/home/**/lib/python3.12/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-khosra_a/garbage-82a5592f-5337-4d9c-934e-7a6ace59c9a7/popen-gw0/remote7
<class 'OSError'>: [Errno 39] Directory not empty: 'remote7'
warnings.warn(
/home/**/lib/python3.12/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-khosra_a/garbage-82a5592f-5337-4d9c-934e-7a6ace59c9a7/popen-gw0
<class 'OSError'>: [Errno 39] Directory not empty: 'popen-gw0'
warnings.warn(
/home/**/lib/python3.12/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-khosra_a/garbage-82a5592f-5337-4d9c-934e-7a6ace59c9a7/popen-gw4/remote8
<class 'OSError'>: [Errno 39] Directory not empty: 'remote8'
..
that pytest cannot clean the garbage.
To be investigated. Also pinging @unkcpz
Hey if Its not deleting Why not delete it Manually and then runs the Test
Because we don't want to do it manually, and because it should not happen. :-)
Because we don't want to do it manually, and because it should not happen. :-)
Can't we can use Force method to delete
The issue me relate to https://github.com/pytest-dev/pytest/issues/12381, which may or may not resolved from our side. If someone what to pick this issue, would be nice to have a deep understanding on problem of data racing introduced by pytest-xdist and how to avoid it nicely.
Well I am new to this and don’t have deep understanding but still I will try to resolve this issue
hello @khsrali , is this issue still open? If yes, can I proceed with this ?
Hi @crs7617,
I think also @ayushjariyal showed some interest working on this. I don't know if he's still working on it or not.
@khsrali I am working on it. Right now, my semester exams are going on, so I am unable to give my full time to this. However, I am trying my best.
It's all good, no hurry! take your time.
@khsrali Thanks for the update! if there's anything I can help with, feel free to let me know.
@khsrali, I noticed that @ayushjariyal is currently working on issue #6728. I just wanted to clarify if issue #6751 is separate from that, or if they are related. If they are distinct, I’d be happy to proceed with #6751. Let me know what you think!
They are independent issues. I don't know. Maybe @ayushjariyal should answer, if he's also working on that. For me, either way is ok.
alright, thanks for the clarification !
@crs7617 in case you also have a solution for https://github.com/aiidateam/aiida-core/issues/6728, please feel free to provide it. I think solving that issue is kinda high priority.
@crs7617 in case you also have a solution for #6728, please feel free to provide it. I think solving that issue is kinda high priority.
sure , I had an idea about #6751 , I am just going through #6728 rn
Hi @crs7617 I had a solution for https://github.com/aiidateam/aiida-core/issues/6728 in mind, so I put it on https://github.com/aiidateam/aiida-core/pull/6776 you can give us your opinion on that solution!
if you already have a solution of this current issue https://github.com/aiidateam/aiida-core/issues/6751, please don't hesitate to provide it. Cheers!
Hey @khsrali ,
I investigated the issue thoroughly and found that Aiida's codebase does not have any errors related to garbage file management. The problem lies in Pyenv, where some directories are not being deleted properly because they are still not empty when Pytest attempts to remove them in pathlib.py.
To resolve this, I updated the function to forcefully delete those files,
and after the update, the warnings no longer appeared.
Could you please let me know if I missed anything or made any mistakes?
Hi @ayushjariyal,
Thanks a lot for looking into this.
May you please direct me where this function, rm_rf is defined? is this something you wrote? or is it part of pyenv?
if that's the case, maybe it makes more sense to fix this in the upstream
Hi @khsrali ,
You're welcome! The rm_rf function is part of pyenv and can be found at:
/home/user/.pyenv/versions/3.9.20/lib/python3.9/site-packages/_pytest/pathlib.py
Since it belongs to pyenv, it might make sense to fix this upstream, but I'm not quite sure how to go about it.
You can find it on github here: https://github.com/pytest-dev/pytest/blob/main/src/_pytest/pathlib.py#L162
Alright!
Thanks @ayushjariyal ! in that case, I think we should open an issue and ask pytest.
Can you please take care of that? Explaining the issue clearly and your proposed solution. Please also include your setup info. Both python version and pytest version.
Once the issue is opened, please also put a link here, so we can track to see what happens.
Cheers!
Sure! I'll open and issue with pytest.
I opened an issue regarding this problem. You can find it here: https://github.com/pytest-dev/pytest/issues/13269
@adityagh006, chatgpt? 🙃
It's ok to use chatgpt for coding and development. However, the proper use of chatgpt is to actually try and develop and you mange to refine and make it work. The plain suggestions, as you put here, we could also get ourselves 💁