Testing a Flask Application using pytest

Introduction

I recently started using pytest and it is an incredible test framework for python! After reading Brian Okken’s book titled “Python Testing with pytest“, I was convinced that I wanted to start using pytest instead of the built-in unittest module that comes with python. In this blog post, I’ll explain how to test a Flask application using pytest.

pytest is a test framework for python that you use to write test cases, but also to run the test cases. After setting up your test structure, pytest makes it really easy to write tests and provides so much flexibility for running the tests. Using pytest, I’ve found that is satisfies the key aspects of a good test environment:

  • tests are fun to write
  • tests can be written quickly by using helper functions (fixtures)
  • tests can be executed with a single command
  • tests run quickly

For reference, the Flask application that is referenced in this blog post can be found on GitLab: https://gitlab.com/patkennedy79/flask_user_management_example

https://www.patricksoftwareblog.com/testing-a-flask-application-using-pytest/

    原文作者:python人工智能命理
    原文地址: https://www.jianshu.com/p/0fdb62602389
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞