`StatusError` exceptions are impossible to debug via stack trace and message in tests
When a test fails with pytest_httpserver due to no handler being found, it's impossible to debug the error in the test output and/or stack trace, because they don't include information about why the pytest_httpserver handler failed to match the request.
Example:
FAILED tests/test_client.py::test_authentication[user-secret-credentials-DELETE] - harborapi.exceptions.InternalServerError: Server error '500 INTERNAL SERVER ERROR' for url 'http://localhost:41541/api/v2.0/foo': No handler found for this request
And the stack trace just shows harborapi.exceptions.check_response_status calling httpx.Response.raise_for_status().
Custom fixture to debug this?
We could add a custom fixture that eavesdrops on StatusErrors and finds the reason it failed:
@pytest.fixture(autouse=True)
def debug_status_error(request):
try:
yield
except StatusError as e:
# do stuff here
raise e
There are two challenges with this: we need to go through the stack and attempt to find the pytest_httpserver.httpserver instance. Once we find the httpserver, we might not even have a handler to check if we used expect_oneshot_request, as the handler is removed after receiving a request on that URL path (seemingly even if it fails to match in other respects than URL path).