-
Notifications
You must be signed in to change notification settings - Fork 80
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
unconsistent behavior between uvicorn and pytest #501
Comments
ticapix
changed the title
unconsistent behavior when testing
unconsistent behavior between uvicorn and pytest
Jun 23, 2024
Hey, @ticapix, I found your question interesting. So, I've spent some time trying to figure out the root cause. Here's it... Blacksheep sets cdef void set_headers_for_response_content(Response message):
cdef Content content = message.content
if not content:
message._add_header(b'content-length', b'0')
return
message._add_header(b'content-type', content.type or b'application/octet-stream')
if should_use_chunked_encoding(content):
message._add_header(b'transfer-encoding', b'chunked')
else:
message._add_header(b'content-length', str(content.length).encode()) |
@ticapix take a look my PR #502 ❯ pytest -svvv
====================================================================== test session starts ======================================================================
platform darwin -- Python 3.12.4, pytest-8.2.2, pluggy-1.5.0 -- /Users/User/.virtualenvs/blacksheep-issues/bin/python
cachedir: .pytest_cache
rootdir: /Users/User/workspace/neoteroi/BlackSheepIssues
plugins: asyncio-0.23.7
asyncio: mode=Mode.STRICT
collected 1 item
test_issue_501.py::test_health_check <Headers [(b'content-type', b'text/plain; charset=utf-8'), (b'content-length', b'32')]>
PASSED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
In a
server.py
, I have a simple health checkand reusing the
TestClient
from https://www.neoteroi.dev/blacksheep/testing/#using-the-testclient-with-pytest, I have a simple testBug
When running with
pytest -sv
, I'm getting an error becauseresponse.headers
is empty.Expected
However, when I run the server with
uvicorn server:app
and I try withwget
, I do get acontent-type
header.$ wget -qS -O - http://127.0.0.1:8000/health HTTP/1.1 200 OK date: Sun, 23 Jun 2024 21:11:01 GMT server: uvicorn content-type: text/plain; charset=utf-8 content-length: 32 2024-06-23T21:11:02.151666+00:00
Has anyone an idea of the component/code adding this header after I return my
response
object and not present when testing ?Thank you,
Pierre
The text was updated successfully, but these errors were encountered: