Python FASTAPI Testing
Introduction
This page is to capture how to go about testing with FAST API
Comparison to Jest
Here is a table to help compare terminology
| Concept | Jest | pytest |
|---|---|---|
| Test setup | beforeEach, beforeAll
|
Fixtures (function, module, session scope) |
| Test teardown | afterEach, afterAll
|
Fixture finalizers / yield fixtures |
| Dependency injection | Manual mocks, passing objects | Fixture injection by name |
| Auto‑applied setup | Global beforeEach in setup files
|
@pytest.fixture(autouse=True)
|
| Mocking | jest.mock, jest.spyOn
|
monkeypatch.setattr, unittest.mock.patch
|
| Test data factories | Helper functions | Fixtures returning objects |