#11488·wagtail

Documentation request: pytest fixtures for Wagtail pages

Author: thibaudcolasCreated Jan 19, 2024Updated Sep 16, 2026
LabelsDocumentationcomponent:PageDX

There are a lot of requests about documentation for programmatic page creation. I’d like to add one more request for the "pytest fixtures" recipe of using Wagtail pages in unit tests.

Here’s an example I found on the internet: https://github.com/wagtail/wagtail-personalisation/blob/dd4530203f1479c4f8604be324f81594edf2ae6e/tests/fixtures.py#L12-L23

python
@pytest.fixture(scope='function')
def site():
    root_page = ContentPageFactory(parent=None, slug='')
    site = SiteFactory(is_default_site=True, root_page=root_page)

    page1 = ContentPageFactory(parent=root_page, slug='page-1')
    page2 = ContentPageFactory(parent=root_page, slug='page-2')
    ContentPageFactory(parent=page1, slug='page-1-1')
    ContentPageFactory(parent=page2, slug='page-2-1')

    RegularPageFactory(parent=root_page, slug='regular')
    return site

This is in combination with wagtail-factories though (see that fixture’s factories), I’d also be interested in an example without factories.

Pertinent section of the Wagtail docs

I’m not sure. Turning Testing your Wagtail site into a documentation section with examples across multiple variants?

Details

Related:

Working on this

Anyone can contribute to this, if they have awareness of pytest and Wagtail’s Page models. View our contributing guidelines, add a comment to the issue once you’re ready to start.