NEW: Fenrir v1.2.2 is now available — Logo & Favicon Patch! Read the changelog
testing.md
docs testing.md

Testing

Creating Test Cases

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from fenrir import Fenrir
from fenrir.testing import TestClient

app = Fenrir()

@app.get("/")
async def read_root():
    return {"message": "Hello World"}

def test_read_root():
    client = TestClient(app)
    response = client.get("/")
    assert response.status_code == 200
    assert response.json() == {"message": "Hello World"}

Testing with pytest

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import pytest
from fenrir.testing import TestClient
from app import app

@pytest.fixture
def client():
    return TestClient(app)

def test_get_user(client):
    response = client.get("/users/1")
    assert response.status_code == 200
    assert response.json()["user_id"] == 1

def test_create_user(client):
    response = client.post(
        "/users",
        json={"name": "John", "email": "john@example.com"}
    )
    assert response.status_code == 201
    assert response.json()["id"]

Testing File Uploads

1
2
3
4
5
6
7
8
def test_upload_file(client):
    with open("test.txt", "rb") as f:
        response = client.post(
            "/upload",
            files={"file": f}
        )
    assert response.status_code == 200
    assert response.json()["filename"] == "test.txt"

Testing WebSockets

1
2
3
4
5
6
7
from fenrir.testing import TestClient

def test_websocket():
    client = TestClient(app)
    with client.websocket_connect("/ws") as websocket:
        data = websocket.receive_text()
        assert data
Edit on GitHub Last Updated: Jun 04, 2026
© 2026 Fenrir Project.
main*
v1.2.2
Ln 1, Col 1
UTF-8
Prettier
Light Mode
Markdown