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
Sending >=500 KB file with test client causes warning #1785
Comments
From
It seems the warning only shows when Python: 3.7.7 |
Working on this. Will keep updated. |
A few findings:
@davidism thoughts on next steps? |
I can't reproduce this issue on Python 3.6+, Werkzeug 1.0.x or latest. I tried both the original example and a simplified one that only used Werkzeug. Werkzeug exampleimport unittest
from werkzeug import Request
from werkzeug import Response
from werkzeug import Client
@Request.application
def app(request):
return Response("Hello, World!")
with open("zero.txt", "wb") as f:
f.write(b"0" * 1_000_000)
class APITest(unittest.TestCase):
def test_file(self):
c = Client(app)
with open("zero.txt", "rb") as f:
r = c.post(data={"file": f})
assert r.get_data(as_text=True) == "Hello, World!"
if __name__ == "__main__":
unittest.main()
As far as I can tell, the open files passed to Now that the test client always returns You can close the input stream in the current 1.0.x release, it's just a bit more complicated. You need to pass environ, result = client.post("/", data={"file": f})
assert result.get_data() == expect
environ["wsgi.input"].close() |
I'm not sure if I should make my proposed fix right now, since I can't reproduce the issue. I'll see if I can have someone else test it. |
Never mind, I just tried it again and now I can reproduce it consistently. Weird. But if I install the latest development Werkzeug instead of 1.0.1, the issue goes away. But if I run with |
Expected Behavior
An endpoint with a POST method is created, along with a unittest to test its behavior. I create two dummy files (you can include your own files) one with size 499 KB, one with size 500 KB. I pass both files to the endpoint in my unittest (by running
python3 -m unittest example.py
)Actual Behavior
POST-ing the bigger file (>=500 KB) produces a
ResourceWarning
Console output:
Changing from
f.write(b"0" * 1024 * 500)
tof.write(b"0" * 1024 * 499)
the output isEnvironment
The text was updated successfully, but these errors were encountered: