Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Building Data Science Applications with FastAPI - Second Edition

You're reading from  Building Data Science Applications with FastAPI - Second Edition

Product type Book
Published in Jul 2023
Publisher Packt
ISBN-13 9781837632749
Pages 422 pages
Edition 2nd Edition
Languages
Author (1):
François Voron François Voron
Profile icon François Voron

Table of Contents (21) Chapters

Preface 1. Part 1: Introduction to Python and FastAPI
2. Chapter 1: Python Development Environment Setup 3. Chapter 2: Python Programming Specificities 4. Chapter 3: Developing a RESTful API with FastAPI 5. Chapter 4: Managing Pydantic Data Models in FastAPI 6. Chapter 5: Dependency Injection in FastAPI 7. Part 2: Building and Deploying a Complete Web Backend with FastAPI
8. Chapter 6: Databases and Asynchronous ORMs 9. Chapter 7: Managing Authentication and Security in FastAPI 10. Chapter 8: Defining WebSockets for Two-Way Interactive Communication in FastAPI 11. Chapter 9: Testing an API Asynchronously with pytest and HTTPX 12. Chapter 10: Deploying a FastAPI Project 13. Part 3: Building Resilient and Distributed Data Science Systems with FastAPI
14. Chapter 11: Introduction to Data Science in Python 15. Chapter 12: Creating an Efficient Prediction API Endpoint with FastAPI 16. Chapter 13: Implementing a Real-Time Object Detection System Using WebSockets with FastAPI 17. Chapter 14: Creating a Distributed Text-to-Image AI System Using the Stable Diffusion Model 18. Chapter 15: Monitoring the Health and Performance of a Data Science System 19. Index 20. Other Books You May Enjoy

An introduction to unit testing with pytest

As we mentioned in the introduction, writing unit tests is an essential task in software development to deliver high-quality software. To help us be productive and efficient, a lot of libraries exist that provide tools and shortcuts dedicated to testing. In the Python standard library, a module exists for unit testing called unittest. Even though it’s quite common in Python code bases, many Python developers tend to prefer pytest, which provides a more lightweight syntax and powerful tools for advanced use cases.

In the following examples, we’ll write a unit test for a function called add, both with unittest and pytest, so that you can see how they compare on a basic use case. First, we’ll install pytest:

(venv) $ pip install pytest

Now, let’s see our simple add function, which simply performs an addition:

chapter09_introduction.py

def add(a: int, b: int) -> int:    return a...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}