diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index b4aaa1e..ed3033a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -22,6 +22,8 @@ import uuid from pathlib import Path from toot import api, App, User from toot.console import run_command +from toot.exceptions import ApiError, ConsoleError +from toot.output import print_out # Host name of a test instance to run integration tests against # DO NOT USE PUBLIC INSTANCES!!! @@ -84,7 +86,13 @@ def friend(app): @pytest.fixture def run(app, user, capsys): def _run(command, *params, as_user=None): - run_command(app, as_user or user, command, params or []) + # The try/catch duplicates logic from console.main to convert exceptions + # to printed error messages. TODO: could be deduped + try: + run_command(app, as_user or user, command, params or []) + except (ConsoleError, ApiError) as e: + print_out(str(e)) + out, err = capsys.readouterr() assert err == "" return strip_ansi(out) diff --git a/tests/integration/test_auth.py b/tests/integration/test_auth.py index afe5c39..c786c4b 100644 --- a/tests/integration/test_auth.py +++ b/tests/integration/test_auth.py @@ -1,15 +1,11 @@ -import pytest - from tests.integration.conftest import TRUMPET from toot import api -from toot.exceptions import ConsoleError from toot.utils import get_text def test_update_account_no_options(run): - with pytest.raises(ConsoleError) as exc: - run("update_account") - assert str(exc.value) == "Please specify at least one option to update the account" + out = run("update_account") + assert out == "Please specify at least one option to update the account" def test_update_account_display_name(run, app, user): diff --git a/tests/integration/test_lists.py b/tests/integration/test_lists.py index dc2e3f5..6f98998 100644 --- a/tests/integration/test_lists.py +++ b/tests/integration/test_lists.py @@ -1,7 +1,4 @@ - -import pytest from tests.integration.conftest import register_account -from toot.exceptions import ConsoleError def test_lists_empty(run): @@ -36,9 +33,8 @@ def test_list_create_delete(run): out = run("lists") assert out == "You have no lists defined." - with pytest.raises(ConsoleError) as exc: - run("list_delete", "mango") - assert str(exc.value) == "List not found" + out = run("list_delete", "mango") + assert out == "List not found" def test_list_add_remove(run, app): @@ -57,14 +53,12 @@ def test_list_add_remove(run, app): assert acc.username in out # Account doesn't exist - with pytest.raises(ConsoleError) as exc: - run("list_add", "foo", "does_not_exist") - assert str(exc.value) == "Account not found" + out = run("list_add", "foo", "does_not_exist") + assert out == "Account not found" # List doesn't exist - with pytest.raises(ConsoleError) as exc: - run("list_add", "does_not_exist", acc.username) - assert str(exc.value) == "List not found" + out = run("list_add", "does_not_exist", acc.username) + assert out == "List not found" out = run("list_remove", "foo", acc.username) assert out == f'✓ Removed account "{acc.username}"'