How To Write Unit Tests in Python • Pytest Tutorial

2022/04/09 に公開
視聴回数 127,103
0
0
Learn how to test your Python code by writing unit tests with the Pytest framework.

In this video I'll be covering how to write and run unit tests, how to check if an Error is raised, how to use test fixtures, and how to mock dependencies.

💻 Code: https://github.com/pixegami/simple-pytest-tutorial
👉 Pytest Documentation: https://docs.pytest.org/
👉 Unittest Mock: https://docs.python.org/3/library/unittest.mock.html

📚 Chapters

00:00 Introduction
02:45 Install Pytest and setup the project
04:14 Running your first unit test
06:50 Implement your test (with "assert")
11:24 How to test that an Error is raised
18:30 How to run a specific unit test file/method
19:50 How to see print statements in pytest
20:27 Implementing "get_total_price" test
23:10 Using pytest fixtures to set up context for your tests
27:00 When your tests depends on another module
30:50 How to mock dependencies (using unittest Mock)
34:30 Wrap-up

#pytest #python