cookiecutter-flask-skeleton icon indicating copy to clipboard operation
cookiecutter-flask-skeleton copied to clipboard

add cli tests

Open mjhea0 opened this issue 7 years ago • 1 comments

https://www.reddit.com/r/flask/comments/89f6by/af_how_do_i_test_my_cli_scripts/

mjhea0 avatar Apr 04 '18 17:04 mjhea0

Some examples what to test...

Let's take the drop_db function from the manage.py module. I would not push this to production without a proper test. For what to test there are different opinions.

First, kind a "smoke test" - test for a 0 exit code.

Second, create a db via fixture, use the drop_db cli command, assert db is gone.

Third, if you like @sandimetz 's testing matrix (cf https://www.youtube.com/watch?v=URSWYvyc42M ), and you do not want to test outgoing commands (ie the db.drop_all() call), you'd have to create a mock and assert db.drop_all was called.

Fortunately, Click makes testing easy: http://click.palletsprojects.com/en/7.x/testing/

jugmac00 avatar Mar 11 '19 14:03 jugmac00