@@ -236,24 +236,37 @@ def test_fails_to_create_destination_empty_required_fields(test_linode_client: L
236236 )
237237
238238
239- @_SKIP_STREAM_TESTS
240- def test_fails_to_create_stream_invalid_destination (test_linode_client : LinodeClient ):
239+ @pytest . fixture ( scope = "session" )
240+ def invalid_destination_error (test_linode_client : LinodeClient ):
241241 """
242- Test that creating a stream with a non-existent destination ID results in a 400 ApiError.
243- Requires no other streams to be present on account. If a stream is already present test is skipped.
242+ Session-scoped fixture to attempt invalid stream creation deterministically
243+ before any valid streams are created. Yields the resulting exception so
244+ assertions can be handled safely within the test case.
244245 """
245246 from linode_api4 .errors import ApiError
246247
247248 _skip_if_streams_exist (test_linode_client )
248249
249- with pytest . raises ( ApiError ) as excinfo :
250+ try :
250251 test_linode_client .monitor .stream_create (
251252 label = get_test_label (),
252253 type = LogsStreamType .audit_logs ,
253254 destinations = [999999999 ],
254255 )
255- assert excinfo .value .status == 400
256- assert excinfo .value .errors == ['Destination not found' ]
256+ yield None
257+ except ApiError as excinfo :
258+ yield excinfo
259+
260+ @_SKIP_STREAM_TESTS
261+ def test_fails_to_create_stream_invalid_destination (invalid_destination_error ):
262+ """
263+ Test that creating a stream with a non-existent destination ID results in a 400 ApiError.
264+ Requires no other streams to be present on account.
265+ """
266+ assert invalid_destination_error is not None , "Expected an ApiError but none was raised"
267+
268+ assert invalid_destination_error .status == 400
269+ assert invalid_destination_error .errors == ['Destination not found' ]
257270
258271
259272@pytest .fixture (scope = "session" )
@@ -267,7 +280,10 @@ def create_secondary_destination(
267280
268281
269282@pytest .fixture (scope = "session" )
270- def create_stream (test_linode_client : LinodeClient , test_destination : LogsDestination ):
283+ def create_stream (test_linode_client : LinodeClient ,
284+ test_destination : LogsDestination ,
285+ invalid_destination_error #This ensures run order to keep negative test case deterministic
286+ ):
271287 _skip_if_streams_exist (test_linode_client )
272288
273289 stream = test_linode_client .monitor .stream_create (
0 commit comments