Plain is headed towards 1.0! Subscribe for development updates →

plain.pytest

Test with pytest.

Overview

Use the plain test command to run tests with pytest and automatically load a .env.test (if available).

def test_example(settings):
    settings.DEBUG = True
    assert settings.DEBUG is True

Fixtures

settings

Use the settings fixture to access and modify settings during tests. Any changes made to settings are automatically restored after the test completes.

def test_example(settings):
    settings.DEBUG = True
    assert settings.DEBUG is True

testbrowser

A lightweight wrapper around Playwright that starts a gunicorn side-process to point the browser at. The testbrowser fixture provides access to a TestBrowser instance.

Note that playwright, pytest-playwright, and gunicorn are not dependencies of this package but are required if you want to use this fixture.

def test_example(testbrowser):
    page = testbrowser.new_page()
    page.goto('/')
    assert page.title() == 'Home Page'

The testbrowser includes useful methods:

If plain.models is installed, then the testbrowser will also load the isolated_db fixture and pass a DATABASE_URL to the gunicorn process.

Installation

Install the plain.pytest package from PyPI:

uv add plain.pytest --dev