Skip to content
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

StatusError exceptions are impossible to debug via stack trace and message in tests #49

Open
pederhan opened this issue Apr 26, 2023 · 0 comments
Labels
tests Unit and integration testing

Comments

@pederhan
Copy link
Member

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).

@pederhan pederhan added the tests Unit and integration testing label Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Unit and integration testing
Projects
None yet
Development

No branches or pull requests

1 participant