-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
pytest doesn't display ResourceWarnings that unittest does #5676
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
Comments
Pathlib closes the fd on the method used in the domonstratiob |
Oh wait, I did miss tread, please check if it happens with disabled assertion rewriting |
Seems to have the same behavior
|
interesting: def test():
open(__file__).read()
if __name__ == '__main__':
exit(test()) $ python3 -Wonce t.py
t.py:2: ResourceWarning: unclosed file <_io.TextIOWrapper name='t.py' mode='r' encoding='UTF-8'>
open(__file__).read() $ pytest -qq t.py
. [100%]
$ pytest -Wonce -qq t.py
. [100%]
=============================== warnings summary ===============================
t.py::test
/tmp/x/t.py:2: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/x/t.py' mode='r' encoding='UTF-8'>
open(__file__).read()
-- Docs: https://docs.pytest.org/en/latest/warnings.html
$ pytest -Werror -qq t.py
. |
We register/unregister handlers at various stages, such as test setup/call/teardown, collection, etc. I think the last hook called where we still capture warnings is pytest/src/_pytest/warnings.py Lines 131 to 137 in cb15e7c
What I want to say is that we are not capturing warnings during the entire session, but only at some points. I wonder if we could start warning capture during |
I'm more surprised that when I elevate it to |
I'd like to take a stab at fixing this. How should I go about that? |
I think I would follow these steps:
I've investigated a bit the |
there's a hint in #8021 -- pytest should probably implement |
This Stack Overflow post might provide some clues:
|
pytest doesn't seem to be displaying ResourceWarnings that unittest does display.
I'm using pytest 5.0.1 on python 3.6.8 on Ubuntu 18.04.2 LTS running in WSL on Windows 10.
Function being tested that triggers ResourceWarning in unittest but not pytest:
pytest test code:
unittest test code:
pytest output:
unittest output:
The text was updated successfully, but these errors were encountered: