Skip to content

Commit 7445176

Browse files
authored
Tests run_until must be guard-claused with cleanup routine (#616)
1 parent 32faa39 commit 7445176

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

tests/test_usage_scenario.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,34 @@ def test_depends_on_huge():
329329

330330
def test_depends_on_error_not_running():
331331
runner = Tests.setup_runner(usage_scenario='depends_on_error_not_running.yml', dry_run=True)
332-
with pytest.raises(RuntimeError) as e:
333-
Tests.run_until(runner, 'setup_services')
332+
try:
333+
with pytest.raises(RuntimeError) as e:
334+
Tests.run_until(runner, 'setup_services')
335+
finally:
336+
runner.cleanup()
337+
334338
assert "Dependent container 'test-container-2' of 'test-container-1' is not running" in str(e.value) , \
335339
Tests.assertion_info('test-container-2 is not running', str(e.value))
336340

337341
def test_depends_on_error_cyclic_dependency():
338342
runner = Tests.setup_runner(usage_scenario='depends_on_error_cycle.yml', dry_run=True)
339-
with pytest.raises(RuntimeError) as e:
340-
Tests.run_until(runner, 'setup_services')
343+
try:
344+
with pytest.raises(RuntimeError) as e:
345+
Tests.run_until(runner, 'setup_services')
346+
finally:
347+
runner.cleanup()
348+
341349
assert "Cycle found in depends_on definition with service 'test-container-1'" in str(e.value) , \
342350
Tests.assertion_info('cycle in depends_on with test-container-1', str(e.value))
343351

344352
def test_depends_on_error_unsupported_long_form():
345353
runner = Tests.setup_runner(usage_scenario='depends_on_error_unsupported_long_form.yml', dry_run=True)
346-
with pytest.raises(RuntimeError) as e:
347-
Tests.run_until(runner, 'setup_services')
354+
try:
355+
with pytest.raises(RuntimeError) as e:
356+
Tests.run_until(runner, 'setup_services')
357+
finally:
358+
runner.cleanup()
359+
348360
assert "long form" in str(e.value) , \
349361
Tests.assertion_info('long form is not supported', str(e.value))
350362

@@ -454,9 +466,12 @@ def test_uri_local_dir():
454466

455467
def test_uri_local_dir_missing():
456468
runner = Tests.setup_runner(usage_scenario='basic_stress.yml', uri='/tmp/missing')
457-
with pytest.raises(FileNotFoundError) as e:
458-
runner.run()
459-
expected_exception = 'No such file or directory: \'/tmp/missing\''
469+
try:
470+
with pytest.raises(FileNotFoundError) as e:
471+
runner.run()
472+
expected_exception = 'No such file or directory: \'/tmp/missing\''
473+
finally:
474+
runner.cleanup()
460475
assert expected_exception in str(e.value),\
461476
Tests.assertion_info(f"Exception: {expected_exception}", str(e.value))
462477

0 commit comments

Comments
 (0)