Skip to content

Commit 3bb530d

Browse files
authored
Merge pull request #1006 from cderici/clean-up-warnings
#1006 #### Description This clears up from the test output the flood of warnings from pytest that looks like (e.g. [example](https://github.com/juju/python-libjuju/actions/runs/7463235016/job/20307443804#step:5:982)): ``` tests/unit/test_bundle.py:738 tests/unit/test_bundle.py:738: PytestDeprecationWarning: test_run is asynchronous and explicitly requests the "event_loop" fixture. Asynchronous fixtures and test functions should use "asyncio.get_running_loop()" instead. @pytest.mark.asyncio ``` #### QA Steps No functionality changes. Though there were a couple of tests that I needed to manually get the running loop (where the test actually was using the `event_loop`), so we need to make sure those are still passing. #### Notes & Discussions Maybe need to be back-ported? I'm not sure yet.
2 parents 62d64d0 + 2f7c236 commit 3bb530d

17 files changed

Lines changed: 171 additions & 214 deletions

tests/base.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@
1111
from juju.client.jujudata import FileJujuData
1212
from juju.controller import Controller
1313

14-
from juju.jasyncio import SingletonEventLoop
15-
16-
17-
@pytest.fixture(scope="session")
18-
def event_loop():
19-
"""
20-
This fixture forces all the asyncio tests
21-
to use the same events loop
22-
"""
23-
24-
loop = SingletonEventLoop().loop
25-
yield loop
26-
loop.close()
27-
2814

2915
def is_bootstrapped():
3016
try:

tests/integration/test_application.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
@base.bootstrapped
22-
async def test_action(event_loop):
22+
async def test_action():
2323
async with base.CleanModel() as model:
2424
app = await model.deploy('juju-qa-test')
2525
await jasyncio.sleep(10)
@@ -28,7 +28,7 @@ async def test_action(event_loop):
2828

2929

3030
@base.bootstrapped
31-
async def test_get_set_config(event_loop):
31+
async def test_get_set_config():
3232
async with base.CleanModel() as model:
3333
app = await model.deploy(
3434
'ubuntu',
@@ -53,7 +53,7 @@ async def test_get_set_config(event_loop):
5353

5454
@base.bootstrapped
5555
@pytest.mark.skip('Update charm')
56-
async def test_status_is_not_unset(event_loop):
56+
async def test_status_is_not_unset():
5757
async with base.CleanModel() as model:
5858
app = await model.deploy(
5959
'ubuntu-0',
@@ -67,7 +67,7 @@ async def test_status_is_not_unset(event_loop):
6767

6868
@base.bootstrapped
6969
@pytest.mark.skip('Update charm')
70-
async def test_status(event_loop):
70+
async def test_status():
7171
async with base.CleanModel() as model:
7272
app = await model.deploy('ch:juju-qa-test')
7373

@@ -82,7 +82,7 @@ def app_ready():
8282

8383
@base.bootstrapped
8484
@pytest.mark.skip('Update charm')
85-
async def test_add_units(event_loop):
85+
async def test_add_units():
8686
from juju.unit import Unit
8787

8888
async with base.CleanModel() as model:
@@ -100,7 +100,7 @@ async def test_add_units(event_loop):
100100

101101

102102
@base.bootstrapped
103-
async def test_deploy_charmhub_charm(event_loop):
103+
async def test_deploy_charmhub_charm():
104104
async with base.CleanModel() as model:
105105
app = await model.deploy('ubuntu')
106106
await model.block_until(lambda: (len(app.units) > 0 and
@@ -110,7 +110,7 @@ async def test_deploy_charmhub_charm(event_loop):
110110

111111
@base.bootstrapped
112112
@pytest.mark.skip('Skip until a similar k8s solution is found')
113-
async def test_upgrade_charm_switch_channel(event_loop):
113+
async def test_upgrade_charm_switch_channel():
114114
# Note for future:
115115
# This test requires a charm that has different
116116
# revisions for different channels/risks.
@@ -154,7 +154,7 @@ async def test_upgrade_charm_switch_channel(event_loop):
154154

155155
@base.bootstrapped
156156
@pytest.mark.skip('Update charm')
157-
async def test_upgrade_charm_revision(event_loop):
157+
async def test_upgrade_charm_revision():
158158
async with base.CleanModel() as model:
159159
app = await model.deploy('ubuntu')
160160
await model.block_until(lambda: (len(app.units) > 0 and
@@ -166,7 +166,7 @@ async def test_upgrade_charm_revision(event_loop):
166166

167167
@base.bootstrapped
168168
@pytest.mark.skip('Update charm')
169-
async def test_upgrade_charm_switch(event_loop):
169+
async def test_upgrade_charm_switch():
170170
async with base.CleanModel() as model:
171171
app = await model.deploy('ubuntu')
172172
await model.block_until(lambda: (len(app.units) > 0 and
@@ -179,7 +179,7 @@ async def test_upgrade_charm_switch(event_loop):
179179

180180

181181
@base.bootstrapped
182-
async def test_upgrade_local_charm(event_loop):
182+
async def test_upgrade_local_charm():
183183
async with base.CleanModel() as model:
184184
tests_dir = Path(__file__).absolute().parent
185185
charm_path = tests_dir / 'upgrade-charm'
@@ -192,7 +192,7 @@ async def test_upgrade_local_charm(event_loop):
192192

193193

194194
@base.bootstrapped
195-
async def test_upgrade_local_charm_resource(event_loop):
195+
async def test_upgrade_local_charm_resource():
196196
async with base.CleanModel() as model:
197197
charm_path = INTEGRATION_TEST_DIR / 'file-resource-charm'
198198
resources = {"file-res": "test.file"}
@@ -212,7 +212,7 @@ async def test_upgrade_local_charm_resource(event_loop):
212212
@base.bootstrapped
213213
@pytest.mark.asyncio
214214
@pytest.mark.skip('Update charm')
215-
async def test_upgrade_charm_resource(event_loop):
215+
async def test_upgrade_charm_resource():
216216
async with base.CleanModel() as model:
217217
app = await model.deploy('cs:~juju-qa/bionic/upgrade-charm-resource-test-0')
218218

@@ -232,7 +232,7 @@ async def test_upgrade_charm_resource(event_loop):
232232

233233
@base.bootstrapped
234234
@pytest.mark.asyncio
235-
async def test_refresh_with_resource_argument(event_loop):
235+
async def test_refresh_with_resource_argument():
236236
async with base.CleanModel() as model:
237237
app = await model.deploy('juju-qa-test', resources={'foo-file': '2'})
238238
res2 = await app.get_resources()
@@ -244,7 +244,7 @@ async def test_refresh_with_resource_argument(event_loop):
244244

245245
@base.bootstrapped
246246
@pytest.mark.asyncio
247-
async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
247+
async def test_upgrade_charm_resource_same_rev_no_update():
248248
async with base.CleanModel() as model:
249249
app = await model.deploy('keystone', channel='victoria/stable')
250250
ress = await app.get_resources()
@@ -255,7 +255,7 @@ async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
255255

256256
@base.bootstrapped
257257
@pytest.mark.asyncio
258-
async def test_refresh_charmhub_to_local(event_loop):
258+
async def test_refresh_charmhub_to_local():
259259
charm_path = INTEGRATION_TEST_DIR / 'charm'
260260
async with base.CleanModel() as model:
261261
app = await model.deploy('ubuntu', application_name='ubu-path')
@@ -269,7 +269,7 @@ async def test_refresh_charmhub_to_local(event_loop):
269269

270270
@base.bootstrapped
271271
@pytest.mark.asyncio
272-
async def test_local_refresh(event_loop):
272+
async def test_local_refresh():
273273
charm_path = INTEGRATION_TEST_DIR / 'charm'
274274
async with base.CleanModel() as model:
275275
app = await model.deploy('ubuntu')
@@ -285,7 +285,7 @@ async def test_local_refresh(event_loop):
285285

286286
@base.bootstrapped
287287
@pytest.mark.asyncio
288-
async def test_trusted(event_loop):
288+
async def test_trusted():
289289
async with base.CleanModel() as model:
290290
await model.deploy('ubuntu', trust=True)
291291

@@ -299,7 +299,7 @@ async def test_trusted(event_loop):
299299

300300

301301
@base.bootstrapped
302-
async def test_app_destroy(event_loop):
302+
async def test_app_destroy():
303303
async with base.CleanModel() as model:
304304
app = await model.deploy('ubuntu')
305305
a_name = app.name # accessing name is impossible after the app is destroyed
@@ -314,7 +314,7 @@ async def test_app_destroy(event_loop):
314314

315315

316316
@base.bootstrapped
317-
async def test_app_remove_wait_flag(event_loop):
317+
async def test_app_remove_wait_flag():
318318
async with base.CleanModel() as model:
319319
app = await model.deploy('ubuntu')
320320
a_name = app.name
@@ -325,7 +325,7 @@ async def test_app_remove_wait_flag(event_loop):
325325

326326

327327
@base.bootstrapped
328-
async def test_app_charm_name(event_loop):
328+
async def test_app_charm_name():
329329
async with base.CleanModel() as model:
330330
app = await model.deploy('ubuntu')
331331
await model.wait_for_idle(status="active")

tests/integration/test_charmhub.py

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

1010

1111
@base.bootstrapped
12-
async def test_info(event_loop):
12+
async def test_info():
1313
async with base.CleanModel() as model:
1414
_, name = await model.charmhub.get_charm_id("ubuntu")
1515
assert name == "ubuntu"
@@ -30,7 +30,7 @@ async def test_info(event_loop):
3030

3131

3232
@base.bootstrapped
33-
async def test_info_with_channel(event_loop):
33+
async def test_info_with_channel():
3434
async with base.CleanModel() as model:
3535
charm_info = await model.charmhub.info("juju-qa-test", "2.0/stable")
3636
assert charm_info['name'] == 'juju-qa-test'
@@ -48,7 +48,7 @@ async def test_info_with_channel(event_loop):
4848

4949

5050
@base.bootstrapped
51-
async def test_info_not_found(event_loop):
51+
async def test_info_not_found():
5252
async with base.CleanModel() as model:
5353
with pytest.raises(JujuError) as err:
5454
await model.charmhub.info("badnameforapp")
@@ -57,7 +57,7 @@ async def test_info_not_found(event_loop):
5757

5858
@base.bootstrapped
5959
@pytest.mark.skip('CharmHub facade no longer exists')
60-
async def test_find(event_loop):
60+
async def test_find():
6161
async with base.CleanModel() as model:
6262
result = await model.charmhub.find("kube")
6363

@@ -69,7 +69,7 @@ async def test_find(event_loop):
6969

7070
@base.bootstrapped
7171
@pytest.mark.skip('CharmHub facade no longer exists')
72-
async def test_find_bundles(event_loop):
72+
async def test_find_bundles():
7373
async with base.CleanModel() as model:
7474
result = await model.charmhub.find("kube", charm_type="bundle")
7575

@@ -81,7 +81,7 @@ async def test_find_bundles(event_loop):
8181

8282
@base.bootstrapped
8383
@pytest.mark.skip('CharmHub facade no longer exists')
84-
async def test_find_all(event_loop):
84+
async def test_find_all():
8585
async with base.CleanModel() as model:
8686
result = await model.charmhub.find("")
8787

@@ -93,7 +93,7 @@ async def test_find_all(event_loop):
9393

9494
@base.bootstrapped
9595
@pytest.mark.skip('This tries to test juju controller logic')
96-
async def test_subordinate_charm_zero_units(event_loop):
96+
async def test_subordinate_charm_zero_units():
9797
# normally in pylibjuju deploy num_units defaults to 1, we switch
9898
# that to 0 behind the scenes if we see that the charmhub charm
9999
# we're deploying is a subordinate charm
@@ -119,14 +119,14 @@ async def test_subordinate_charm_zero_units(event_loop):
119119

120120

121121
@base.bootstrapped
122-
async def test_subordinate_false_field_exists(event_loop):
122+
async def test_subordinate_false_field_exists():
123123
async with base.CleanModel() as model:
124124
assert await model.charmhub.is_subordinate("rsyslog-forwarder-ha")
125125
assert not await model.charmhub.is_subordinate("mysql-innodb-cluster")
126126

127127

128128
@base.bootstrapped
129-
async def test_list_resources(event_loop):
129+
async def test_list_resources():
130130
async with base.CleanModel() as model:
131131
resources = await model.charmhub.list_resources('hello-kubecon')
132132
assert isinstance(resources, list) and len(resources) > 0

tests/integration/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@base.bootstrapped
10-
async def test_user_info(event_loop):
10+
async def test_user_info():
1111
async with base.CleanModel() as model:
1212
controller_conn = await model.connection().controller()
1313

tests/integration/test_connection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
@base.bootstrapped
28-
async def test_monitor(event_loop):
28+
async def test_monitor():
2929
async with base.CleanModel() as model:
3030
conn = model.connection()
3131
assert conn.monitor.status == 'connected'
@@ -35,7 +35,7 @@ async def test_monitor(event_loop):
3535

3636

3737
@base.bootstrapped
38-
async def test_monitor_catches_error(event_loop):
38+
async def test_monitor_catches_error():
3939

4040
async with base.CleanModel() as model:
4141
conn = model.connection()
@@ -56,7 +56,7 @@ async def test_monitor_catches_error(event_loop):
5656

5757
@base.bootstrapped
5858
@pytest.mark.skip('Update charm')
59-
async def test_full_status(event_loop):
59+
async def test_full_status():
6060
async with base.CleanModel() as model:
6161
await model.deploy(
6262
'ubuntu',
@@ -71,7 +71,7 @@ async def test_full_status(event_loop):
7171

7272

7373
@base.bootstrapped
74-
async def test_reconnect(event_loop):
74+
async def test_reconnect():
7575
async with base.CleanModel() as model:
7676
kwargs = model.connection().connect_params()
7777
conn = await Connection.connect(**kwargs)
@@ -87,7 +87,7 @@ async def test_reconnect(event_loop):
8787

8888
@base.bootstrapped
8989
@pytest.mark.skip('tests the websocket protocol, not pylibjuju, needs to be revised')
90-
async def test_redirect(event_loop):
90+
async def test_redirect():
9191
controller = Controller()
9292
await controller.connect()
9393
kwargs = controller.connection().connect_params()
@@ -233,7 +233,7 @@ def _find_free_port(self):
233233

234234

235235
@base.bootstrapped
236-
async def test_verify_controller_cert(event_loop):
236+
async def test_verify_controller_cert():
237237
jujudata = FileJujuData()
238238
controller_name = jujudata.current_controller()
239239
endpoint = jujudata.controllers()[controller_name]['api-endpoints'][0]

0 commit comments

Comments
 (0)