File tree Expand file tree Collapse file tree 3 files changed +26
-13
lines changed
airbyte_cdk/test/standard_tests Expand file tree Collapse file tree 3 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -148,8 +148,9 @@ def run_test_job(
148148
149149 return result
150150
151- assert not result .errors , (
152- f"Expected no errors but got { len (result .errors )} : \n " + _errors_to_str (result )
153- )
151+ if not test_scenario .expect_exception :
152+ assert not result .errors , (
153+ f"Expected no errors but got { len (result .errors )} : \n " + _errors_to_str (result )
154+ )
154155
155156 return result
Original file line number Diff line number Diff line change 1313from typing import cast
1414
1515import yaml
16+ from airbyte_protocol_dataclasses .models .airbyte_protocol import AirbyteConnectionStatus
1617from boltons .typeutils import classproperty
1718
18- from airbyte_cdk .models import (
19- AirbyteMessage ,
20- Type ,
21- )
19+ from airbyte_cdk .models import Status
2220from airbyte_cdk .test import entrypoint_wrapper
2321from airbyte_cdk .test .standard_tests ._job_runner import IConnector , run_test_job
2422from airbyte_cdk .test .standard_tests .models import (
@@ -117,12 +115,22 @@ def test_check(
117115 "check" ,
118116 test_scenario = scenario ,
119117 )
120- conn_status_messages : list [AirbyteMessage ] = [
121- msg for msg in result ._messages if msg .type == Type .CONNECTION_STATUS
122- ] # noqa: SLF001 # Non-public API
123- assert len (conn_status_messages ) == 1 , (
124- f"Expected exactly one CONNECTION_STATUS message. Got: { result ._messages } "
118+ assert len (result .connection_status_messages ) == 1 , (
119+ f"Expected exactly one CONNECTION_STATUS message. Got { len (result .connection_status_messages )} : \n "
120+ + "\n " .join ([str (m ) for m in result ._messages ])
121+ + "\n Errors: "
122+ + str (result .errors )
123+ or "None"
124+ )
125+ conn_status = cast (
126+ AirbyteConnectionStatus , result .connection_status_messages [0 ].connectionStatus
125127 )
128+ if (
129+ scenario .expect_exception
130+ and conn_status .status == Status .SUCCEEDED
131+ and not result .errors
132+ ):
133+ raise AssertionError (f"Expected error in `check` but got success." )
126134
127135 @classmethod
128136 def get_connector_root_dir (cls ) -> Path :
Original file line number Diff line number Diff line change @@ -151,6 +151,11 @@ def test_fail_read_with_bad_catalog(
151151 scenario : ConnectorTestScenario ,
152152 ) -> None :
153153 """Standard test for `read` when passed a bad catalog file."""
154+ # Recreate the scenario with the same config but set the status to "failed".
155+ scenario = ConnectorTestScenario (
156+ config_dict = scenario .get_config_dict (empty_if_missing = False ),
157+ status = "failed" ,
158+ )
154159 invalid_configured_catalog = ConfiguredAirbyteCatalog (
155160 streams = [
156161 # Create ConfiguredAirbyteStream which is deliberately invalid
@@ -171,7 +176,6 @@ def test_fail_read_with_bad_catalog(
171176 ]
172177 )
173178 # Set expected status to "failed" to ensure the test fails if the connector.
174- scenario .status = "failed"
175179 result : entrypoint_wrapper .EntrypointOutput = run_test_job (
176180 self .create_connector (scenario ),
177181 "read" ,
You can’t perform that action at this time.
0 commit comments