官术网_书友最值得收藏!

Testing the code

To test our application, we use the excellent pytest framework, which is the gold standard in test runners for Python applications.

Basically, pytest has a lot of plugins and add-ons to deal with a lot of situations. We will be using pytest-flask, which helps with running tests for Flask applications.

To run all the tests, just call pytest in the command line:

$ pytest
============== test session starts ==============
....
==== 17 passed, 177 warnings in 1.50 seconds =====

Note that pytest has a lot of features available to deal with a lot of situations while testing. Things running a subset of matched tests (the  -k option), running the last failed tests ( --lf), or stopping after the first failure ( -x) are incredibly useful when working with tests. I highly recommend checking its full documentation ( https://docs.pytest.org/en/latest/) and discovering all its possibilities.

There are also a lot of plugins and extensions for using databases or frameworks, reporting code coverage, profiling, BDD, and many others. It is worth finding out about them.

We configure the basic usage, including always enabling flags in the pytest.ini file and the fixtures in conftest.py.

主站蜘蛛池模板: 西盟| 宁武县| 霍邱县| 唐山市| 长春市| 滁州市| 黄浦区| 东源县| 贵定县| 巴中市| 临沧市| 临桂县| 肇州县| 梅河口市| 上虞市| 忻城县| 荔浦县| 扬中市| 贵溪市| 丽江市| 杭州市| 饶平县| 阳城县| 重庆市| 阿勒泰市| 睢宁县| 揭西县| 景洪市| 临澧县| 临洮县| 抚宁县| 长宁区| 鄂伦春自治旗| 临城县| 建湖县| 榕江县| 河池市| 景泰县| 阿拉善盟| 兴城市| 吴桥县|