spiral-project / ihatemoney

A simple shared budget manager web application
https://ihatemoney.org
Other
1.19k stars 268 forks source link

Migrate to pytest #1148

Closed Glandos closed 1 year ago

Glandos commented 1 year ago

Currently, we are using pytest for launching tests, but they are all written with Flask-Testing and unittest.

Since Flask-Testing is nearly dead, and Flask is moving fastly, we should move away from it, and use another way to write test. As far as I can tell, the base documentation for testing Flask can easily use fixtures of pytest.

In this issue, I want to discuss what we are currently using, and what could be done to move to pytest.

However, there might be other library I'm not aware of.

Glandos commented 1 year ago

unittest.MagicMock and patch

Not yet identified

flask_testing.TestCase

unittest assertions

Not yet identified

hamma741 commented 1 year ago

It's great that you are considering moving away from Flask-Testing and exploring other options for writing tests in Flask. As you mentioned, using fixtures with pytest is a popular approach for testing Flask applications.

In addition to pytest, there are other testing frameworks that you may want to consider, such as nose or unittest2. However, pytest is widely used and offers many features that make it a popular choice among developers.

To get started with using pytest for testing Flask, you can take a look at the official Flask documentation on testing with pytest (https://flask.palletsprojects.com/en/2.1.x/testing/pytest/). This guide provides an overview of how to use pytest with Flask, including how to create test fixtures, how to write tests using the Flask test client, and how to run tests using pytest.

In general, moving to pytest involves refactoring your existing tests to use pytest fixtures and syntax. This may take some time, but it can provide significant benefits in terms of test organization, readability, and maintainability.

Some benefits of using pytest over Flask-Testing include:

Pytest offers a more powerful and flexible testing framework, with many built-in features for test discovery, test organization, and test execution. Pytest has a large and active community, with many plugins and extensions available for customizing and extending its functionality. Pytest is compatible with many other testing tools and frameworks, making it easy to integrate with your existing development workflow. Overall, moving to pytest can be a great way to improve your testing process and ensure that your Flask applications are robust, reliable, and easy to maintain.