Flask development version (future 0.13 or 1.0) simplifies their logging handling (see pallets/flask#2436). This causes troubles when testing output from click commands with pytest:
Flask will only add the StreamHandler to the application logger if and only if no other logger is already installed.
pytest by default adds a logging handler to the root logger. Because of above bullet, Flask will not add the StreamHandler.
Hence, a click command which uses the logger to output errors to the console will thus not work during tests.
Problem
Flask development version (future 0.13 or 1.0) simplifies their logging handling (see pallets/flask#2436). This causes troubles when testing output from click commands with pytest:
Hence, a click command which uses the logger to output errors to the console will thus not work during tests.
I.e. given a Click command similar to this:
and a test similar to this:
Above test will work in Flask 0.12, but not Flask 0.13/1.0.
Solution
Adding the default handler in your application fixture will fix the issue:
Pseudo code: