Skip to content

Commit d37ebcc

Browse files
committed
Update async tests to use builtin python suite
As of Python 3.8, `AsyncMock` and many other async testing tools are available as standard libraries. This PR removes the third-party library `asynctest` and replaces it with those available in the standard python library. As part of this, the tests will now run on Python 3.11, which they previously did not. Additionally, warnings during tests are significantly reduced (from hundreds, to tens).
1 parent c09dbc2 commit d37ebcc

23 files changed

Lines changed: 92 additions & 272 deletions

tests/base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ def models(self):
144144
return all_models
145145

146146

147-
class AsyncMock(mock.MagicMock):
148-
async def __call__(self, *args, **kwargs):
149-
return super().__call__(*args, **kwargs)
150-
151-
152147
@contextmanager
153148
def patch_file(filename):
154149
"""

tests/integration/test_application.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
@base.bootstrapped
16-
@pytest.mark.asyncio
1716
async def test_action(event_loop):
1817
async with base.CleanModel() as model:
1918
ubuntu_app = await model.deploy(
@@ -53,7 +52,6 @@ async def test_action(event_loop):
5352

5453

5554
@base.bootstrapped
56-
@pytest.mark.asyncio
5755
async def test_get_set_config(event_loop):
5856
async with base.CleanModel() as model:
5957
app = await model.deploy(
@@ -78,7 +76,6 @@ async def test_get_set_config(event_loop):
7876

7977

8078
@base.bootstrapped
81-
@pytest.mark.asyncio
8279
@pytest.mark.skip('Update charm')
8380
async def test_status_is_not_unset(event_loop):
8481
async with base.CleanModel() as model:
@@ -93,7 +90,6 @@ async def test_status_is_not_unset(event_loop):
9390

9491

9592
@base.bootstrapped
96-
@pytest.mark.asyncio
9793
@pytest.mark.skip('Update charm')
9894
async def test_status(event_loop):
9995
async with base.CleanModel() as model:
@@ -109,7 +105,6 @@ def app_ready():
109105

110106

111107
@base.bootstrapped
112-
@pytest.mark.asyncio
113108
@pytest.mark.skip('Update charm')
114109
async def test_add_units(event_loop):
115110
from juju.unit import Unit
@@ -129,7 +124,6 @@ async def test_add_units(event_loop):
129124

130125

131126
@base.bootstrapped
132-
@pytest.mark.asyncio
133127
async def test_deploy_charmhub_charm(event_loop):
134128
async with base.CleanModel() as model:
135129
app = await model.deploy('ubuntu')
@@ -139,7 +133,6 @@ async def test_deploy_charmhub_charm(event_loop):
139133

140134

141135
@base.bootstrapped
142-
@pytest.mark.asyncio
143136
@pytest.mark.skip('Skip until a similar k8s solution is found')
144137
async def test_upgrade_charm_switch_channel(event_loop):
145138
# Note for future:
@@ -184,7 +177,6 @@ async def test_upgrade_charm_switch_channel(event_loop):
184177

185178

186179
@base.bootstrapped
187-
@pytest.mark.asyncio
188180
@pytest.mark.skip('Update charm')
189181
async def test_upgrade_charm_revision(event_loop):
190182
async with base.CleanModel() as model:
@@ -197,7 +189,6 @@ async def test_upgrade_charm_revision(event_loop):
197189

198190

199191
@base.bootstrapped
200-
@pytest.mark.asyncio
201192
@pytest.mark.skip('Update charm')
202193
async def test_upgrade_charm_switch(event_loop):
203194
async with base.CleanModel() as model:
@@ -212,7 +203,6 @@ async def test_upgrade_charm_switch(event_loop):
212203

213204

214205
@base.bootstrapped
215-
@pytest.mark.asyncio
216206
async def test_upgrade_local_charm(event_loop):
217207
async with base.CleanModel() as model:
218208
tests_dir = Path(__file__).absolute().parent
@@ -226,7 +216,6 @@ async def test_upgrade_local_charm(event_loop):
226216

227217

228218
@base.bootstrapped
229-
@pytest.mark.asyncio
230219
async def test_upgrade_local_charm_resource(event_loop):
231220
async with base.CleanModel() as model:
232221
tests_dir = Path(__file__).absolute().parent
@@ -246,7 +235,6 @@ async def test_upgrade_local_charm_resource(event_loop):
246235

247236

248237
@base.bootstrapped
249-
@pytest.mark.asyncio
250238
async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
251239
async with base.CleanModel() as model:
252240
app = await model.deploy('keystone', channel='victoria/stable')
@@ -257,7 +245,6 @@ async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
257245

258246

259247
@base.bootstrapped
260-
@pytest.mark.asyncio
261248
async def test_trusted(event_loop):
262249
async with base.CleanModel() as model:
263250
await model.deploy('ubuntu', trust=True)
@@ -272,7 +259,6 @@ async def test_trusted(event_loop):
272259

273260

274261
@base.bootstrapped
275-
@pytest.mark.asyncio
276262
async def test_app_destroy(event_loop):
277263
async with base.CleanModel() as model:
278264
app = await model.deploy('ubuntu')
@@ -288,7 +274,6 @@ async def test_app_destroy(event_loop):
288274

289275

290276
@base.bootstrapped
291-
@pytest.mark.asyncio
292277
async def test_app_remove_wait_flag(event_loop):
293278
async with base.CleanModel() as model:
294279
app = await model.deploy('ubuntu')
@@ -300,7 +285,6 @@ async def test_app_remove_wait_flag(event_loop):
300285

301286

302287
@base.bootstrapped
303-
@pytest.mark.asyncio
304288
async def test_app_charm_name(event_loop):
305289
async with base.CleanModel() as model:
306290
app = await model.deploy('ubuntu')

tests/integration/test_charmhub.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
@base.bootstrapped
9-
@pytest.mark.asyncio
109
async def test_info(event_loop):
1110
async with base.CleanModel() as model:
1211
_, name = await model.charmhub.get_charm_id("ubuntu")
@@ -28,7 +27,6 @@ async def test_info(event_loop):
2827

2928

3029
@base.bootstrapped
31-
@pytest.mark.asyncio
3230
async def test_info_with_channel(event_loop):
3331
async with base.CleanModel() as model:
3432
charm_info = await model.charmhub.info("juju-qa-test", "2.0/stable")
@@ -47,7 +45,6 @@ async def test_info_with_channel(event_loop):
4745

4846

4947
@base.bootstrapped
50-
@pytest.mark.asyncio
5148
async def test_info_not_found(event_loop):
5249
async with base.CleanModel() as model:
5350
with pytest.raises(JujuError) as err:
@@ -56,7 +53,6 @@ async def test_info_not_found(event_loop):
5653

5754

5855
@base.bootstrapped
59-
@pytest.mark.asyncio
6056
@pytest.mark.skip('CharmHub facade no longer exists')
6157
async def test_find(event_loop):
6258
async with base.CleanModel() as model:
@@ -69,7 +65,6 @@ async def test_find(event_loop):
6965

7066

7167
@base.bootstrapped
72-
@pytest.mark.asyncio
7368
@pytest.mark.skip('CharmHub facade no longer exists')
7469
async def test_find_bundles(event_loop):
7570
async with base.CleanModel() as model:
@@ -82,7 +77,6 @@ async def test_find_bundles(event_loop):
8277

8378

8479
@base.bootstrapped
85-
@pytest.mark.asyncio
8680
@pytest.mark.skip('CharmHub facade no longer exists')
8781
async def test_find_all(event_loop):
8882
async with base.CleanModel() as model:
@@ -95,7 +89,6 @@ async def test_find_all(event_loop):
9589

9690

9791
@base.bootstrapped
98-
@pytest.mark.asyncio
9992
@pytest.mark.skip('This tries to test juju controller logic')
10093
async def test_subordinate_charm_zero_units(event_loop):
10194
# normally in pylibjuju deploy num_units defaults to 1, we switch
@@ -123,15 +116,13 @@ async def test_subordinate_charm_zero_units(event_loop):
123116

124117

125118
@base.bootstrapped
126-
@pytest.mark.asyncio
127119
async def test_subordinate_false_field_exists(event_loop):
128120
async with base.CleanModel() as model:
129121
assert await model.charmhub.is_subordinate("rsyslog-forwarder-ha")
130122
assert not await model.charmhub.is_subordinate("mysql-innodb-cluster")
131123

132124

133125
@base.bootstrapped
134-
@pytest.mark.asyncio
135126
async def test_list_resources(event_loop):
136127
async with base.CleanModel() as model:
137128
resources = await model.charmhub.list_resources('hello-kubecon')

tests/integration/test_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
@base.bootstrapped
9-
@pytest.mark.asyncio
109
async def test_user_info(event_loop):
1110
async with base.CleanModel() as model:
1211
controller_conn = await model.connection().controller()

tests/integration/test_connection.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323

2424
@base.bootstrapped
25-
@pytest.mark.asyncio
2625
async def test_monitor(event_loop):
2726
async with base.CleanModel() as model:
2827
conn = model.connection()
@@ -33,7 +32,6 @@ async def test_monitor(event_loop):
3332

3433

3534
@base.bootstrapped
36-
@pytest.mark.asyncio
3735
async def test_monitor_catches_error(event_loop):
3836

3937
async with base.CleanModel() as model:
@@ -54,7 +52,6 @@ async def test_monitor_catches_error(event_loop):
5452

5553

5654
@base.bootstrapped
57-
@pytest.mark.asyncio
5855
@pytest.mark.skip('Update charm')
5956
async def test_full_status(event_loop):
6057
async with base.CleanModel() as model:
@@ -71,7 +68,6 @@ async def test_full_status(event_loop):
7168

7269

7370
@base.bootstrapped
74-
@pytest.mark.asyncio
7571
async def test_reconnect(event_loop):
7672
async with base.CleanModel() as model:
7773
kwargs = model.connection().connect_params()
@@ -87,7 +83,6 @@ async def test_reconnect(event_loop):
8783

8884

8985
@base.bootstrapped
90-
@pytest.mark.asyncio
9186
@pytest.mark.skip('tests the websocket protocol, not pylibjuju, needs to be revised')
9287
async def test_redirect(event_loop):
9388
controller = Controller()
@@ -235,7 +230,6 @@ def _find_free_port(self):
235230

236231

237232
@base.bootstrapped
238-
@pytest.mark.asyncio
239233
async def test_verify_controller_cert(event_loop):
240234
jujudata = FileJujuData()
241235
controller_name = jujudata.current_controller()

tests/integration/test_controller.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
@base.bootstrapped
16-
@pytest.mark.asyncio
1716
async def test_add_remove_user(event_loop):
1817
async with base.CleanController() as controller:
1918
username = 'test{}'.format(uuid.uuid4())
@@ -33,7 +32,6 @@ async def test_add_remove_user(event_loop):
3332

3433

3534
@base.bootstrapped
36-
@pytest.mark.asyncio
3735
async def test_disable_enable_user(event_loop):
3836
async with base.CleanController() as controller:
3937
username = 'test-disable{}'.format(uuid.uuid4())
@@ -57,7 +55,6 @@ async def test_disable_enable_user(event_loop):
5755

5856

5957
@base.bootstrapped
60-
@pytest.mark.asyncio
6158
async def test_change_user_password(event_loop):
6259
async with base.CleanController() as controller:
6360
username = 'test-password{}'.format(uuid.uuid4())
@@ -78,7 +75,6 @@ async def test_change_user_password(event_loop):
7875

7976

8077
@base.bootstrapped
81-
@pytest.mark.asyncio
8278
async def test_reset_user_password(event_loop):
8379
async with base.CleanController() as controller:
8480
username = 'test{}'.format(uuid.uuid4())
@@ -107,7 +103,6 @@ async def test_reset_user_password(event_loop):
107103

108104

109105
@base.bootstrapped
110-
@pytest.mark.asyncio
111106
async def test_list_models(event_loop):
112107
async with base.CleanController() as controller:
113108
async with base.CleanModel() as model:
@@ -116,7 +111,6 @@ async def test_list_models(event_loop):
116111

117112

118113
@base.bootstrapped
119-
@pytest.mark.asyncio
120114
async def test_get_model(event_loop):
121115
async with base.CleanController() as controller:
122116
by_name, by_uuid = None, None
@@ -150,7 +144,6 @@ async def _wait_for_model_gone(controller, model_name):
150144

151145

152146
@base.bootstrapped
153-
@pytest.mark.asyncio
154147
async def test_destroy_model_by_name(event_loop):
155148
async with base.CleanController() as controller:
156149
model_name = 'test-{}'.format(uuid.uuid4())
@@ -166,7 +159,6 @@ async def test_destroy_model_by_name(event_loop):
166159

167160

168161
@base.bootstrapped
169-
@pytest.mark.asyncio
170162
async def test_add_destroy_model_by_uuid(event_loop):
171163
async with base.CleanController() as controller:
172164
model_name = 'test-{}'.format(uuid.uuid4())
@@ -183,7 +175,6 @@ async def test_add_destroy_model_by_uuid(event_loop):
183175

184176

185177
@base.bootstrapped
186-
@pytest.mark.asyncio
187178
async def test_add_remove_cloud(event_loop):
188179
async with base.CleanController() as controller:
189180
cloud_name = 'test-{}'.format(uuid.uuid4())
@@ -201,7 +192,6 @@ async def test_add_remove_cloud(event_loop):
201192

202193

203194
@base.bootstrapped
204-
@pytest.mark.asyncio
205195
async def test_secrets_backend_lifecycle(event_loop):
206196
"""Testing the add_secret_backends is particularly
207197
costly in term of resources. This test sets a vault
@@ -279,7 +269,6 @@ async def test_secrets_backend_lifecycle(event_loop):
279269

280270

281271
@base.bootstrapped
282-
@pytest.mark.asyncio
283272
async def test_grant_revoke_controller_access(event_loop):
284273
async with base.CleanController() as controller:
285274
username = 'test-grant{}'.format(uuid.uuid4())
@@ -307,7 +296,6 @@ async def test_grant_revoke_controller_access(event_loop):
307296

308297

309298
@base.bootstrapped
310-
@pytest.mark.asyncio
311299
async def test_grant_revoke_model_access(event_loop):
312300
async with base.CleanController() as controller:
313301
username = 'test-grant{}'.format(uuid.uuid4())

0 commit comments

Comments
 (0)