Skip to content

Commit f39f480

Browse files
committed
cleaner error prints
1 parent 594be48 commit f39f480

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

airbyte_cdk/test/declarative/utils/job_runner.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121
)
2222

2323

24+
def _errors_to_str(
25+
entrypoint_output: entrypoint_wrapper.EntrypointOutput,
26+
) -> str:
27+
"""Convert errors from entrypoint output to a string."""
28+
if not entrypoint_output.errors:
29+
# If there are no errors, return an empty string.
30+
return ""
31+
32+
return "\n" + "\n".join(
33+
[
34+
str(error.trace.error).replace(
35+
"\\n",
36+
"\n",
37+
)
38+
for error in entrypoint_output.errors
39+
if error.trace
40+
],
41+
)
42+
43+
2444
@runtime_checkable
2545
class IConnector(Protocol):
2646
"""A connector that can be run in a test scenario.
@@ -53,7 +73,7 @@ def run_test_job(
5373
if isinstance(connector, type) or callable(connector):
5474
# If the connector is a class or a factory lambda, instantiate it.
5575
connector_obj = connector()
56-
elif isinstance(connector, IConnector): # TODO: Get a valid protocol check here
76+
elif isinstance(connector, IConnector):
5777
connector_obj = connector
5878
else:
5979
raise ValueError(
@@ -99,22 +119,18 @@ def run_test_job(
99119
)
100120
if result.errors and not test_scenario.expect_exception:
101121
raise AssertionError(
102-
"\n\n".join(
103-
[str(err.trace.error).replace("\\n", "\n") for err in result.errors if err.trace],
104-
)
122+
f"Expected no errors but got {len(result.errors)}: \n" + _errors_to_str(result)
105123
)
106124

107125
if verb == "check":
108126
# Check is expected to fail gracefully without an exception.
109127
# Instead, we assert that we have a CONNECTION_STATUS message with
110128
# a failure status.
111-
assert not result.errors, "Expected no errors from check. Got:\n" + "\n".join(
112-
[str(error) for error in result.errors]
113-
)
114129
assert len(result.connection_status_messages) == 1, (
115130
"Expected exactly one CONNECTION_STATUS message. Got "
116131
f"{len(result.connection_status_messages)}:\n"
117132
+ "\n".join([str(msg) for msg in result.connection_status_messages])
133+
+ _errors_to_str(result)
118134
)
119135
if test_scenario.expect_exception:
120136
conn_status = result.connection_status_messages[0].connectionStatus
@@ -135,18 +151,9 @@ def run_test_job(
135151
raise AssertionError("Expected exception but got none.")
136152

137153
return result
138-
if result.errors:
139-
raise AssertionError(
140-
"\n\n".join(
141-
[
142-
str(err.trace.error).replace(
143-
"\\n",
144-
"\n",
145-
)
146-
for err in result.errors
147-
if err.trace
148-
],
149-
)
150-
)
154+
155+
assert not result.errors, (
156+
f"Expected no errors but got {len(result.errors)}: \n" + _errors_to_str(result)
157+
)
151158

152159
return result

0 commit comments

Comments
 (0)