Documentation request: pytest fixtures for Wagtail pages
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
@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 siteThis 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:
- #11488
- #11244
- #742
- #1101
- #5535
- #5464
- #7901
- #10628
- https://github.com/wagtail/bakerydemo/issues/534
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.
Source: wagtail/wagtail