Skip to content

Commit 06e6502

Browse files
Akay7sourcery-ai[bot]greptile-apps[bot]pre-commit-ci[bot]bellini666
authored
feat: make messages if there's assert_no_errors more verbose (#4423)
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Thiago Bellini Ribeiro <hackedbellini@gmail.com>
1 parent dccc222 commit 06e6502

4 files changed

Lines changed: 36 additions & 2 deletions

File tree

RELEASE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
release type: minor
3+
social_messages:
4+
x: >-
5+
{project_name} {version} is out! This release adds richer verbose output
6+
to `assert_no_errors`, including full response error details for easier
7+
debugging. 🍓 https://strawberry.rocks/release/{version}
8+
linkedin: >-
9+
{project_name} {version} is out. This release adds richer verbose output
10+
to `assert_no_errors`, including full response error details for easier
11+
debugging.
12+
---
13+
14+
This release adds richer verbose output to `assert_no_errors`. When GraphQL
15+
errors are detected, the assertion now includes full error details, making it
16+
easier to debug failing tests.

strawberry/aiohttp/test/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def query(
2727

2828
if assert_no_errors:
2929
assert resp.status == 200
30-
assert response.errors is None
30+
assert response.errors is None, response.errors
3131

3232
return response
3333

strawberry/test/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def query(
5353
)
5454

5555
if assert_no_errors:
56-
assert response.errors is None
56+
assert response.errors is None, response.errors
5757

5858
return response
5959

tests/test/test_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
"""Test that assert_no_errors includes response.errors in the AssertionError message."""
2+
13
from contextlib import nullcontext
24

35
import pytest
46

57
from strawberry.utils.await_maybe import await_maybe
68

9+
QUERY_TO_NON_EXISTENT_FIELD = "{ nonExistentField { id } }"
10+
11+
NON_EXISTENT_FIELD_ERRORS = [
12+
{
13+
"message": "Cannot query field 'nonExistentField' on type 'Query'.",
14+
"locations": [{"line": 1, "column": 3}],
15+
}
16+
]
17+
718

819
@pytest.mark.parametrize(
920
("assert_no_errors", "expectation"),
@@ -18,3 +29,10 @@ async def test_query_with_assert_no_errors_option(
1829
await await_maybe(
1930
graphql_client.query(query, assert_no_errors=assert_no_errors)
2031
)
32+
33+
34+
async def test_assert_no_errors_includes_response_errors_in_message(graphql_client):
35+
with pytest.raises(AssertionError) as exc_info:
36+
await await_maybe(graphql_client.query(QUERY_TO_NON_EXISTENT_FIELD))
37+
38+
assert exc_info.value.args[0] == NON_EXISTENT_FIELD_ERRORS

0 commit comments

Comments
 (0)