test(fastapi): add PostHog setup, event, and error capture tests - #305
Open
AlexPaiva wants to merge 2 commits into
Open
test(fastapi): add PostHog setup, event, and error capture tests#305AlexPaiva wants to merge 2 commits into
AlexPaiva wants to merge 2 commits into
Conversation
shouldSkip gets a path relative to the example root, so the global `/test/` pattern only matches nested dirs like app/test/. A root-level test/ or tests/ has no leading slash and never matches, so next-app-router/tests ships its Playwright specs in the skill output. Adds an anchored regex for the root-level case, plus a regression test covering nested, root-level and the testing/ near-miss.
Covers what the example exists to demonstrate: the lifespan configures the client and flushes on shutdown, the page and API routes capture their events with the right properties, and the error endpoints hand the exception to capture_exception and surface the returned event id. The routers bind `capture` at import time, so it is patched where it is used rather than on the posthog module. The fixture is autouse, so no test can reach the network, and a temp SQLite file keeps runs isolated. pytest.ini and requirements-dev.txt are skipped for this example; the tests themselves are covered by the global root-level test dir rule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Picks up #24, scoped to one example so the pattern stays reviewable. Builds on #304, without which these files ship inside the packaged skill (the first commit here is that fix, and this diff shrinks once it merges).
Covers what the example exists to demonstrate:
/api/test-errorand/api/trigger-errorhand the exception tocapture_exceptionand surface the returned event id, and?capture=falseskips itTwo implementation notes. The routers bind
captureat import time, so it is patched atapp.routers.api.captureandapp.routers.main.capturerather than on the posthog module.capture_exceptionandflushare read off the module, so those are patched there instead. The fixture is autouse, so no test can reach the network, and a temp SQLite file keeps runs isolated.httpxtriggers a starlette deprecation warning withTestClient, sorequirements-dev.txtpinshttpx2. Verified in a clean venv, 11 passed with no warnings.pytest.iniandrequirements-dev.txtare skipped for this example. The tests themselves are covered by the global rule in #304.If this shape works, the other three Python examples (
flask,django,python) can follow it.