11import re
22import time
33from test .integration .conftest import get_region
4- from test .integration .helpers import get_test_label
4+ from test .integration .helpers import get_test_label , wait_for_condition
55
66import pytest
77
@@ -55,10 +55,11 @@ def test_fails_to_create_domain_without_soa_email(setup_client_and_linode):
5555
5656 timestamp = str (time .time_ns ())
5757 domain_addr = timestamp + "example.com"
58- try :
59- domain = client .domain_create (domain = domain_addr )
60- except ApiError as e :
61- assert e .status == 400
58+
59+ with pytest .raises (ApiError ) as exc_info :
60+ client .domain_create (domain = domain_addr )
61+
62+ assert exc_info .value .status == 400
6263
6364
6465@pytest .mark .smoke
@@ -90,11 +91,16 @@ def test_get_regions(test_linode_client):
9091def test_image_create (setup_client_and_linode ):
9192 client = setup_client_and_linode [0 ]
9293 linode = setup_client_and_linode [1 ]
93-
9494 label = get_test_label ()
9595 description = "Test description"
9696 tags = ["test" ]
97- usable_disk = [v for v in linode .disks if v .filesystem != "swap" ]
97+
98+ def linode_disks_are_ready (linode_instance ):
99+ linode_instance .invalidate ()
100+ disks = [d for d in linode_instance .disks if d .filesystem != "swap" ]
101+ return disks if disks else None
102+
103+ usable_disk = wait_for_condition (5 , 120 , linode_disks_are_ready , linode )
98104
99105 image = client .image_create (
100106 disk = usable_disk [0 ].id , label = label , description = description , tags = tags
@@ -116,23 +122,23 @@ def test_fails_to_create_image_with_non_existing_disk_id(
116122 description = "Test description"
117123 disk_id = 111111
118124
119- try :
125+ with pytest . raises ( ApiError ) as exc_info :
120126 client .image_create (disk = disk_id , label = label , description = description )
121- except ApiError as e :
122- assert 400 <= e .status < 500
127+
128+ # TODO: Specific status code may be used when defect is solved: ARB-7797
129+ assert 400 <= exc_info .value .status < 500
123130
124131
125132def test_fails_to_delete_predefined_images (setup_client_and_linode ):
126133 client = setup_client_and_linode [0 ]
127134
128135 images = client .images ()
129136
130- try :
137+ with pytest . raises ( ApiError , match = "Unauthorized" ) as exc_info :
131138 # new images go on top of the list thus choose last image
132139 images .last ().delete ()
133- except ApiError as e :
134- assert "Unauthorized" in str (e .json )
135- assert e .status == 403
140+
141+ assert exc_info .value .status == 403
136142
137143
138144def test_get_volume (test_linode_client , test_volume ):
@@ -345,16 +351,15 @@ def test_fails_to_create_cluster_with_invalid_version(test_linode_client):
345351 client = test_linode_client
346352 region = get_region (client , {"Kubernetes" }).id
347353
348- try :
349- cluster = client .lke .cluster_create (
354+ with pytest . raises ( ApiError , match = "not valid" ) as exc_info :
355+ client .lke .cluster_create (
350356 region ,
351357 "example-cluster" ,
352358 invalid_version ,
353359 {"type" : "g6-standard-1" , "count" : 3 },
354360 )
355- except ApiError as e :
356- assert "not valid" in str (e .json )
357- assert e .status == 400
361+
362+ assert exc_info .value .status == 400
358363
359364
360365# ObjectStorageGroupTests
0 commit comments