Pytest recommendations #6491
-
|
I'm looking for some recommendations or best practices for testing Reflex apps with pytest. Does anyone can point me to good examples or provide some guidelines? Do we need pytest-asyncio? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Testing Reflex apps with pytestTwo layers cover most needs: 1. Static component tests — call your page/section functions and walk 2. End-to-end with # conftest.py — session-scoped so the dev server boots once
from pathlib import Path
import pytest
from reflex.testing import AppHarness
@pytest.fixture(scope="session")
def my_app():
app_root = Path(__file__).parent.parent # dir containing rxconfig.py
with AppHarness.create(root=app_root) as harness:
yield harness# test_e2e.py
from playwright.sync_api import Page, expect
def test_homepage(my_app, page: Page):
page.goto(my_app.frontend_url)
expect(page.get_by_role("button", name="Sign Up")).to_be_visible()Run: Reference examples in the Reflex repo
Do you need
|
Beta Was this translation helpful? Give feedback.
Testing Reflex apps with pytest
Two layers cover most needs:
1. Static component tests — call your page/section functions and walk
the returned
rx.Componenttree. No browser, sub-second. Catches typosand missing sections.
2. End-to-end with
reflex.testing.AppHarness+ Playwright — bootsthe real app and drives a headless browser.