Colin-b / pytest_httpx

pytest fixture to mock HTTPX
https://colin-b.github.io/pytest_httpx/
MIT License
358 stars 30 forks source link

Make sure the match_headers errors are displayed correctly for lower cased version #107

Closed dolfandringa closed 1 year ago

dolfandringa commented 1 year ago

closes #106

Make sure we still display the original header name and value in errors if httpx converted a header name to lower case, and another parameter doesn't match.

So we display

httpx.TimeoutException: No response can be found for GET request on http://www.google.com with {'MyHeader': 'Something'} headers amongst:
E       Match GET requests on http://www.google.com?q=b with {'MyHeader': 'Something'} headers

instead of

httpx.TimeoutException: No response can be found for GET request on http://www.google.com with {} headers amongst:
E       Match GET requests on http://www.google.com?q=b with {'MyHeader': 'Something'} headers

with this test:

from pytest_httpx import HTTPXMock
import httpx

def test_something(httpx_mock: HTTPXMock):
    httpx_mock.add_response(
        method="GET",
        url="http://www.google.com?q=b",
        match_headers={"MyHeader": "Something"},
    )
    with httpx.Client() as client:
        client.get(
            "http://www.google.com", headers={"MyHeader": "Something"}
        )
Colin-b commented 1 year ago

Also the order of the headers in the displayed message seems to not be consistent (as one test case works with python 3.9 while it fails with python 3.10). It might be good to have a look at this as well :)

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

dolfandringa commented 1 year ago

Thanks for the work @Colin-b

Colin-b commented 1 year ago

Thanks for the work @Colin-b

Back at you :) I will let you know once released, should be done this week

Colin-b commented 1 year ago

Thanks again @dolfandringa , release 0.24.0 is now available on pypi