Skip to content

Commit f21bc42

Browse files
authored
Merge pull request #935 from DanielArndt/update-async-tests
#935 #### Description 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). #### QA Steps Running the unit and integration tests is hopefully sufficient #### Notes & Discussion I went down a rabbit hole here while investigating something totally unrelated. I understand if this change needs a more thorough review which there may or may not be time for, but I thought I'd put up the change since I was having some fun digging in.
2 parents 28f31fa + 42648d0 commit f21bc42

23 files changed

Lines changed: 92 additions & 291 deletions

tests/base.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from contextlib import contextmanager
88
from pathlib import Path
99

10-
import mock
11-
1210
import pytest
1311
from juju.client.jujudata import FileJujuData
1412
from juju.controller import Controller
@@ -147,11 +145,6 @@ def models(self):
147145
return all_models
148146

149147

150-
class AsyncMock(mock.MagicMock):
151-
async def __call__(self, *args, **kwargs):
152-
return super().__call__(*args, **kwargs)
153-
154-
155148
@contextmanager
156149
def patch_file(filename):
157150
"""

tests/integration/test_application.py

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

1717

1818
@base.bootstrapped
19-
@pytest.mark.asyncio
2019
async def test_action(event_loop):
2120
async with base.CleanModel() as model:
2221
app = await model.deploy('juju-qa-test')
@@ -26,7 +25,6 @@ async def test_action(event_loop):
2625

2726

2827
@base.bootstrapped
29-
@pytest.mark.asyncio
3028
async def test_get_set_config(event_loop):
3129
async with base.CleanModel() as model:
3230
app = await model.deploy(
@@ -51,7 +49,6 @@ async def test_get_set_config(event_loop):
5149

5250

5351
@base.bootstrapped
54-
@pytest.mark.asyncio
5552
@pytest.mark.skip('Update charm')
5653
async def test_status_is_not_unset(event_loop):
5754
async with base.CleanModel() as model:
@@ -66,7 +63,6 @@ async def test_status_is_not_unset(event_loop):
6663

6764

6865
@base.bootstrapped
69-
@pytest.mark.asyncio
7066
@pytest.mark.skip('Update charm')
7167
async def test_status(event_loop):
7268
async with base.CleanModel() as model:
@@ -82,7 +78,6 @@ def app_ready():
8278

8379

8480
@base.bootstrapped
85-
@pytest.mark.asyncio
8681
@pytest.mark.skip('Update charm')
8782
async def test_add_units(event_loop):
8883
from juju.unit import Unit
@@ -102,7 +97,6 @@ async def test_add_units(event_loop):
10297

10398

10499
@base.bootstrapped
105-
@pytest.mark.asyncio
106100
async def test_deploy_charmhub_charm(event_loop):
107101
async with base.CleanModel() as model:
108102
app = await model.deploy('ubuntu')
@@ -112,7 +106,6 @@ async def test_deploy_charmhub_charm(event_loop):
112106

113107

114108
@base.bootstrapped
115-
@pytest.mark.asyncio
116109
@pytest.mark.skip('Skip until a similar k8s solution is found')
117110
async def test_upgrade_charm_switch_channel(event_loop):
118111
# Note for future:
@@ -157,7 +150,6 @@ async def test_upgrade_charm_switch_channel(event_loop):
157150

158151

159152
@base.bootstrapped
160-
@pytest.mark.asyncio
161153
@pytest.mark.skip('Update charm')
162154
async def test_upgrade_charm_revision(event_loop):
163155
async with base.CleanModel() as model:
@@ -170,7 +162,6 @@ async def test_upgrade_charm_revision(event_loop):
170162

171163

172164
@base.bootstrapped
173-
@pytest.mark.asyncio
174165
@pytest.mark.skip('Update charm')
175166
async def test_upgrade_charm_switch(event_loop):
176167
async with base.CleanModel() as model:
@@ -185,7 +176,6 @@ async def test_upgrade_charm_switch(event_loop):
185176

186177

187178
@base.bootstrapped
188-
@pytest.mark.asyncio
189179
async def test_upgrade_local_charm(event_loop):
190180
async with base.CleanModel() as model:
191181
tests_dir = Path(__file__).absolute().parent
@@ -199,7 +189,6 @@ async def test_upgrade_local_charm(event_loop):
199189

200190

201191
@base.bootstrapped
202-
@pytest.mark.asyncio
203192
async def test_upgrade_local_charm_resource(event_loop):
204193
async with base.CleanModel() as model:
205194
tests_dir = Path(__file__).absolute().parent
@@ -219,7 +208,6 @@ async def test_upgrade_local_charm_resource(event_loop):
219208

220209

221210
@base.bootstrapped
222-
@pytest.mark.asyncio
223211
async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
224212
async with base.CleanModel() as model:
225213
app = await model.deploy('keystone', channel='victoria/stable')
@@ -230,7 +218,6 @@ async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
230218

231219

232220
@base.bootstrapped
233-
@pytest.mark.asyncio
234221
async def test_trusted(event_loop):
235222
async with base.CleanModel() as model:
236223
await model.deploy('ubuntu', trust=True)
@@ -245,7 +232,6 @@ async def test_trusted(event_loop):
245232

246233

247234
@base.bootstrapped
248-
@pytest.mark.asyncio
249235
async def test_app_destroy(event_loop):
250236
async with base.CleanModel() as model:
251237
app = await model.deploy('ubuntu')
@@ -261,7 +247,6 @@ async def test_app_destroy(event_loop):
261247

262248

263249
@base.bootstrapped
264-
@pytest.mark.asyncio
265250
async def test_app_remove_wait_flag(event_loop):
266251
async with base.CleanModel() as model:
267252
app = await model.deploy('ubuntu')
@@ -273,7 +258,6 @@ async def test_app_remove_wait_flag(event_loop):
273258

274259

275260
@base.bootstrapped
276-
@pytest.mark.asyncio
277261
async def test_app_charm_name(event_loop):
278262
async with base.CleanModel() as model:
279263
app = await model.deploy('ubuntu')

tests/integration/test_charmhub.py

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

1010

1111
@base.bootstrapped
12-
@pytest.mark.asyncio
1312
async def test_info(event_loop):
1413
async with base.CleanModel() as model:
1514
_, name = await model.charmhub.get_charm_id("ubuntu")
@@ -31,7 +30,6 @@ async def test_info(event_loop):
3130

3231

3332
@base.bootstrapped
34-
@pytest.mark.asyncio
3533
async def test_info_with_channel(event_loop):
3634
async with base.CleanModel() as model:
3735
charm_info = await model.charmhub.info("juju-qa-test", "2.0/stable")
@@ -50,7 +48,6 @@ async def test_info_with_channel(event_loop):
5048

5149

5250
@base.bootstrapped
53-
@pytest.mark.asyncio
5451
async def test_info_not_found(event_loop):
5552
async with base.CleanModel() as model:
5653
with pytest.raises(JujuError) as err:
@@ -59,7 +56,6 @@ async def test_info_not_found(event_loop):
5956

6057

6158
@base.bootstrapped
62-
@pytest.mark.asyncio
6359
@pytest.mark.skip('CharmHub facade no longer exists')
6460
async def test_find(event_loop):
6561
async with base.CleanModel() as model:
@@ -72,7 +68,6 @@ async def test_find(event_loop):
7268

7369

7470
@base.bootstrapped
75-
@pytest.mark.asyncio
7671
@pytest.mark.skip('CharmHub facade no longer exists')
7772
async def test_find_bundles(event_loop):
7873
async with base.CleanModel() as model:
@@ -85,7 +80,6 @@ async def test_find_bundles(event_loop):
8580

8681

8782
@base.bootstrapped
88-
@pytest.mark.asyncio
8983
@pytest.mark.skip('CharmHub facade no longer exists')
9084
async def test_find_all(event_loop):
9185
async with base.CleanModel() as model:
@@ -98,7 +92,6 @@ async def test_find_all(event_loop):
9892

9993

10094
@base.bootstrapped
101-
@pytest.mark.asyncio
10295
@pytest.mark.skip('This tries to test juju controller logic')
10396
async def test_subordinate_charm_zero_units(event_loop):
10497
# normally in pylibjuju deploy num_units defaults to 1, we switch
@@ -126,15 +119,13 @@ async def test_subordinate_charm_zero_units(event_loop):
126119

127120

128121
@base.bootstrapped
129-
@pytest.mark.asyncio
130122
async def test_subordinate_false_field_exists(event_loop):
131123
async with base.CleanModel() as model:
132124
assert await model.charmhub.is_subordinate("rsyslog-forwarder-ha")
133125
assert not await model.charmhub.is_subordinate("mysql-innodb-cluster")
134126

135127

136128
@base.bootstrapped
137-
@pytest.mark.asyncio
138129
async def test_list_resources(event_loop):
139130
async with base.CleanModel() as model:
140131
resources = await model.charmhub.list_resources('hello-kubecon')

tests/integration/test_client.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33

44
from juju.client import client
55

6-
import pytest
7-
86
from .. import base
97

108

119
@base.bootstrapped
12-
@pytest.mark.asyncio
1310
async def test_user_info(event_loop):
1411
async with base.CleanModel() as model:
1512
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
@@ -25,7 +25,6 @@
2525

2626

2727
@base.bootstrapped
28-
@pytest.mark.asyncio
2928
async def test_monitor(event_loop):
3029
async with base.CleanModel() as model:
3130
conn = model.connection()
@@ -36,7 +35,6 @@ async def test_monitor(event_loop):
3635

3736

3837
@base.bootstrapped
39-
@pytest.mark.asyncio
4038
async def test_monitor_catches_error(event_loop):
4139

4240
async with base.CleanModel() as model:
@@ -57,7 +55,6 @@ async def test_monitor_catches_error(event_loop):
5755

5856

5957
@base.bootstrapped
60-
@pytest.mark.asyncio
6158
@pytest.mark.skip('Update charm')
6259
async def test_full_status(event_loop):
6360
async with base.CleanModel() as model:
@@ -74,7 +71,6 @@ async def test_full_status(event_loop):
7471

7572

7673
@base.bootstrapped
77-
@pytest.mark.asyncio
7874
async def test_reconnect(event_loop):
7975
async with base.CleanModel() as model:
8076
kwargs = model.connection().connect_params()
@@ -90,7 +86,6 @@ async def test_reconnect(event_loop):
9086

9187

9288
@base.bootstrapped
93-
@pytest.mark.asyncio
9489
@pytest.mark.skip('tests the websocket protocol, not pylibjuju, needs to be revised')
9590
async def test_redirect(event_loop):
9691
controller = Controller()
@@ -238,7 +233,6 @@ def _find_free_port(self):
238233

239234

240235
@base.bootstrapped
241-
@pytest.mark.asyncio
242236
async def test_verify_controller_cert(event_loop):
243237
jujudata = FileJujuData()
244238
controller_name = jujudata.current_controller()

tests/integration/test_controller.py

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

1717

1818
@base.bootstrapped
19-
@pytest.mark.asyncio
2019
async def test_add_remove_user(event_loop):
2120
async with base.CleanController() as controller:
2221
username = 'test{}'.format(uuid.uuid4())
@@ -36,7 +35,6 @@ async def test_add_remove_user(event_loop):
3635

3736

3837
@base.bootstrapped
39-
@pytest.mark.asyncio
4038
async def test_disable_enable_user(event_loop):
4139
async with base.CleanController() as controller:
4240
username = 'test-disable{}'.format(uuid.uuid4())
@@ -60,7 +58,6 @@ async def test_disable_enable_user(event_loop):
6058

6159

6260
@base.bootstrapped
63-
@pytest.mark.asyncio
6461
async def test_change_user_password(event_loop):
6562
async with base.CleanController() as controller:
6663
username = 'test-password{}'.format(uuid.uuid4())
@@ -81,7 +78,6 @@ async def test_change_user_password(event_loop):
8178

8279

8380
@base.bootstrapped
84-
@pytest.mark.asyncio
8581
async def test_reset_user_password(event_loop):
8682
async with base.CleanController() as controller:
8783
username = 'test{}'.format(uuid.uuid4())
@@ -110,7 +106,6 @@ async def test_reset_user_password(event_loop):
110106

111107

112108
@base.bootstrapped
113-
@pytest.mark.asyncio
114109
async def test_list_models(event_loop):
115110
async with base.CleanController() as controller:
116111
async with base.CleanModel() as model:
@@ -119,7 +114,6 @@ async def test_list_models(event_loop):
119114

120115

121116
@base.bootstrapped
122-
@pytest.mark.asyncio
123117
async def test_get_model(event_loop):
124118
async with base.CleanController() as controller:
125119
by_name, by_uuid = None, None
@@ -153,7 +147,6 @@ async def _wait_for_model_gone(controller, model_name):
153147

154148

155149
@base.bootstrapped
156-
@pytest.mark.asyncio
157150
async def test_destroy_model_by_name(event_loop):
158151
async with base.CleanController() as controller:
159152
model_name = 'test-{}'.format(uuid.uuid4())
@@ -169,7 +162,6 @@ async def test_destroy_model_by_name(event_loop):
169162

170163

171164
@base.bootstrapped
172-
@pytest.mark.asyncio
173165
async def test_add_destroy_model_by_uuid(event_loop):
174166
async with base.CleanController() as controller:
175167
model_name = 'test-{}'.format(uuid.uuid4())
@@ -186,7 +178,6 @@ async def test_add_destroy_model_by_uuid(event_loop):
186178

187179

188180
@base.bootstrapped
189-
@pytest.mark.asyncio
190181
async def test_add_remove_cloud(event_loop):
191182
async with base.CleanController() as controller:
192183
cloud_name = 'test-{}'.format(uuid.uuid4())
@@ -204,7 +195,6 @@ async def test_add_remove_cloud(event_loop):
204195

205196

206197
@base.bootstrapped
207-
@pytest.mark.asyncio
208198
async def test_secrets_backend_lifecycle(event_loop):
209199
"""Testing the add_secret_backends is particularly
210200
costly in term of resources. This test sets a vault
@@ -282,7 +272,6 @@ async def test_secrets_backend_lifecycle(event_loop):
282272

283273

284274
@base.bootstrapped
285-
@pytest.mark.asyncio
286275
async def test_grant_revoke_controller_access(event_loop):
287276
async with base.CleanController() as controller:
288277
username = 'test-grant{}'.format(uuid.uuid4())
@@ -310,7 +299,6 @@ async def test_grant_revoke_controller_access(event_loop):
310299

311300

312301
@base.bootstrapped
313-
@pytest.mark.asyncio
314302
async def test_grant_revoke_model_access(event_loop):
315303
async with base.CleanController() as controller:
316304
username = 'test-grant{}'.format(uuid.uuid4())

0 commit comments

Comments
 (0)