I want to write a test to the command when the user aborts it, but I have a problem with the abort
option in click.confirm
when i write full command in console
flask questions deleteall
i got prompt y/N
.
When i select N
option user cancel command and message are displayed in the console Aborted!
.
It looks like below:
Do you want to continue to delete all questions and answers? [y/N]: n
Aborted!
The command code is below:
bp = Blueprint("questions", __name__)
bp.cli.short_help = "Questions utilities"
@bp.cli.command("deleteall")
@with_appcontext
def deleteall():
"""
Delete all examples questions and answers from database
"""
click.confirm('Do you want to continue to delete all questions and answers?', abort=True)
"""
code for command when writing yes in click.confirm - y
"""
i have written test below:
# full command: flask questions deleteall
# y - select 'y' to confirm deleting
def test_cancel_deleteall_command(runner, app_with_db):
result = runner.invoke(args=['questions', 'deleteall', ['N']])
assert result.exit_code == 1
print(result.output)
assert 'Aborted!' in str(result.output)
I have a problem with a test that keeps failing because the results are empty.
test_cancel_deleteall_command ____________________________________________________________________________________
runner = <flask.testing.FlaskCliRunner object at 0x7fbcf01a5b10>, app_with_db = <async_generator object app_with_db at 0x7fbcf06625c0>
def test_cancel_deleteall_command(runner, app_with_db):
# full command: flask question deleteall
# y - select 'y' to confirm deleting
result = runner.invoke(args=['questions', 'deleteall', ['N']])
assert result.exit_code == 1
print(result.output)
> assert 'Aborted!' in str(result.output)
E assert 'Aborted!' in ''
E + where '' = str('')
E + where '' = <Result TypeError("unhashable type: 'list'")>.output
tests/functional/test_cli_commands.py:28: AssertionError
---------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------
======================================================================================= short test summary info =======================================================================================
FAILED tests/functional/test_cli_commands.py::test_cancel_deleteall_command - assert 'Aborted!' in ''
Does anyone have an idea how to get "Aborted!" command message? I tried with result.output
but it doesn't work..