Check return value of App.run() in tests

Sometimes (mostly when debug is off) Cliff can return failure by
returning nonzero exit code from App.run() instead of raising
SystemExit. Catch such errors in octane_app fixture (SafeOctaneApp
class).

Change-Id: If2f87aa9dc0dbd25ddb1ff8909ea9fb1552bf408
This commit is contained in:
Yuriy Taraday 2016-02-17 15:06:18 +03:00
parent 89c8b626e0
commit 40fd9e50c2
2 changed files with 9 additions and 2 deletions

View File

@ -30,9 +30,10 @@ class SafeOctaneApp(app.OctaneApp):
def run(self, argv):
try:
super(SafeOctaneApp, self).run(argv)
exit_code = super(SafeOctaneApp, self).run(argv)
except SystemExit as e:
assert e.code == 0
exit_code = e.code
assert exit_code == 0
@pytest.fixture

View File

@ -13,6 +13,12 @@
import pytest
def test_octane_app_not_exception_return_value(mocker, octane_app):
mocker.patch('octane.app.OctaneApp.run', return_value=2)
with pytest.raises(AssertionError):
octane_app.run([])
def test_octane_app_pass_exceptions_through(mocker, octane_app):
mocker.patch.object(octane_app.command_manager, 'find_command',
side_effect=ValueError)