Cursor rule
.cursor/rules/pytest-integration-tests.mdcPytest Integration Tests
Cursor rules
Quality
73/100
Scores the file, not the repository.Length
690 words
2 headings · 1 code blocksRepository
13
— · pushed 33 days agoLast changed
3 days ago
First indexed 3 days ago.123456## Pytest Integration Tests789- Look to `app/factories/` to generate any required database state10 - Here's an example of how to create + persist a factory `DistributionFactory.save(domain=PYTHON_TEST_SERVER_HOST)`11- Add the `server` factory to each test12- Use the `faker` factory to generate emails, etc.13- Don't add obvious `assert` descriptions14- Do not use the `db_session` fixture here. Instead, use `with test_session():` if you need to setup complex database state15- if a UI timeout is occuring, it could be because it cannot find a element because the rendering has changed. Check the failure screenshot and see if you can correct the test assertion.16- The integration tests can take a very long time to run. Do not abort them if they are taking a long time.17- Use `expect(page.get_by_text("Screening is fully booked")).to_be_visible()` instead of `expect(page.get_by_role("heading")).to_contain_text("Screening is fully booked")`. It's less brittle.18- Do not use `client` fixtures in an integration test. Integration tests should only use the frontend of the website to interact with the application, not the API.19- Use `with page.expect_response("https://example.com/resource") as response_info:` to assert against network activity.20- Do not `next_button.evaluate("el => el.click()")` instead, just `locator.click()`. If this doesn't work, stop your work and let me know.21- Only use `wait_for_loading(page)` if a `LONG_INTEGRATION_TEST_TIMEOUT` on an expectation does not work: `expect(page.get_by_text("Your Matched Doctors")).to_be_visible(timeout=LONG_INTEGRATION_TEST_TIMEOUT)`22 - `LONG_INTEGRATION_TEST_TIMEOUT` should only be used as a last resort. If you have many of these in a test, let me know and I will debug it.23- Prefer fewer integration tests that cover more functionality. Unlike unit tests, where each test is designed to test a very particular piece of functionality, I want integration tests to cover entire workflows. It's preferred to add more steps to an integration test to test an entire workflow.24- Prefer simple locators. If a `filter`, `or_`, etc is required to capture a button in multiple states it indicates something is wrong in the code.25- Use `react_router_url` to generate the frontend url path and do not set `base_url`.26- End all Playwright tests with `from pytest_playwright_artifacts import assert_no_console_errors` and `assert_no_console_errors(request)` (capture is the plugin's `playwright_console_logging` fixture).27 - Test-Specific Ignores: Pass `ignore=[...]` to `assert_no_console_errors` per `pytest-playwright-artifacts` (regex strings, compiled patterns, or `{"file": "...", "message": "..."}` dicts); add a comment explaining why.28 - Global Ignores: Use `playwright_console_ignore` under `[tool.pytest.ini_options]` in `pyproject.toml` (see `pytest-playwright-artifacts` README).2930### Example Integration Test3132Below is an example test. Notice the following:3334- Code comments are used to describe the key user steps that are being tested35- We avoid long timeouts or wait commands36- Fixtures and factories are generated at the beginning of the test37- We assert against database state after each major user action38- Some of the comments (i.e. comments on included fixtures) are included for instructional purposes only and should not be included in the tests you write3940```python41from pytest_playwright_artifacts import assert_no_console_errors424344def test_streaming_checkout_creates_user_and_links_order(45 # this fixture ensures that the underlying python server is started46 server,47 faker,48 page: Page,49 # if you need to create objects (like factories) tied to a common session, include this fixture50 db_truncate_session,51 # for asserting against the console logs52 request: FixtureRequest,53) -> None:54 distribution = DistributionWithWebhooksFactory.save()55 test_email = clerk_test_email()5657 # 1) Run through streaming checkout58 page.goto(react_router_url("/streaming"))5960 page.get_by_placeholder("your@email.com").first.fill(test_email)61 page.get_by_placeholder("your@email.com").last.fill(test_email)6263 # Check TOS64 page.get_by_role("checkbox").last.check()6566 fill_stripe_checkout(page)6768 # 2) Complete checkout69 # the stripe checkout form will expand and cause the purchase button to move below the screen70 safely_scroll_then_click(page.get_by_role("button", name="Complete Purchase"))7172 expect(page.get_by_role("heading", name="You're ready to watch!")).to_be_visible()73 page.get_by_role("link", name="Login & Start Watching").click()7475 # 3) Assert against database and Clerk state7677 # One StreamingOrder should be created for this distribution and email78 assert StreamingOrder.count() == 179 streaming_order = StreamingOrder.get(email=test_email)80 assert streaming_order8182 assert streaming_order.status.value == "completed"83 assert streaming_order.user_id is not None8485 # 4) Login to the app via the Clerk login page86 clerk_login_and_verify(page, test_email)8788 expect(page.get_by_text("Triumph of the Heart").first).to_be_visible()8990 # 5) Play the video91 page.get_by_role("button").filter(has_text="Play").click()9293 # wait for the page to completely load94 wait_for_loading(page)9596 expect(page.get_by_text("Triumph of the Heart").first).to_be_visible()97 expect(page.get_by_text("Play")).not_to_be_visible()9899 assert_no_console_errors(100 request,101 ignore=[102 {103 # if there are console errors specific to the project, exclude them here. Match to the specific URL if you can.104 "file": r"https://iframe.cloudflarestream.com/.*",105 "message": "the server responded with a status of 403",106 }107 ],108 )109```110
Also in iloveitaly/llm-ide-rules
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| iloveitaly/llm-ide-rules.cursor/rules/python.mdc · 13 | Cursor rules | setupstyletypesdo-not | 88/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/alembic-migrations.mdc · 13 | Cursor rules | no sections | 50/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/fastapi.mdc · 13 | Cursor rules | no sections | 24/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/general.mdc · 13 | Cursor rules | teststyledo-notagent-behaviour+1 | 92/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/justfiles.mdc · 13 | Cursor rules | do-not | 31/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/pytest-tests.mdc · 13 | Cursor rules | testarchtesting-strategyapi+1 | 61/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/python-app.mdc · 13 | Cursor rules | styledatabasedocs | 61/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/python-route-tests.mdc · 13 | Cursor rules | api | 24/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/react-router.mdc · 13 | Cursor rules | testing-strategy | 57/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/react.mdc · 13 | Cursor rules | styletesting-strategyuido-not | 60/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/shell.mdc · 13 | Cursor rules | no sections | 4/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/typescript.mdc · 13 | Cursor rules | styletypessecurity | 63/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.github/copilot-instructions.md · 13 | Copilot instructions | teststyledo-notagent-behaviour+1 | 92/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.github/instructions/alembic-migrations.instructions.md · 13 | Copilot instructions | no sections | 50/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.github/instructions/fastapi.instructions.md · 13 | Copilot instructions | no sections | 16/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.github/instructions/justfiles.instructions.md · 13 | Copilot instructions | do-not | 31/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.github/instructions/pytest-integration-tests.instructions.md · 13 | Copilot instructions | teststyletesting-strategy | 65/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.github/instructions/pytest-tests.instructions.md · 13 | Copilot instructions | testarchtesting-strategyapi+1 | 53/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.github/instructions/python-app.instructions.md · 13 | Copilot instructions | styledatabasedocs | 61/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.github/instructions/python-route-tests.instructions.md · 13 | Copilot instructions | api | 16/100 | 3 days ago |
Diff against .cursor/rules/python.mdc Diff against .cursor/rules/alembic-migrations.mdc Diff against .cursor/rules/fastapi.mdc Diff against .cursor/rules/general.mdc Diff against .cursor/rules/justfiles.mdc Diff against .cursor/rules/pytest-tests.mdc Diff against .cursor/rules/python-app.mdc Diff against .cursor/rules/python-route-tests.mdc Diff against .cursor/rules/react-router.mdc Diff against .cursor/rules/react.mdc Diff against .cursor/rules/shell.mdc Diff against .cursor/rules/typescript.mdc Diff against .github/copilot-instructions.md Diff against .github/instructions/alembic-migrations.instructions.md Diff against .github/instructions/fastapi.instructions.md Diff against .github/instructions/justfiles.instructions.md Diff against .github/instructions/pytest-integration-tests.instructions.md Diff against .github/instructions/pytest-tests.instructions.md Diff against .github/instructions/python-app.instructions.md Diff against .github/instructions/python-route-tests.instructions.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago | |
| nerds-odd-e/doughnut.cursor/rules/cli.mdc · 49 | Cursor rules | setupbuildteststyle+4 | 96/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/general.mdc · 13 | Cursor rules | teststyledo-notagent-behaviour+1 | 92/100 | 3 days ago | |
| danielvm-git/bigpowers.cursor/rules/guard-git.mdc · 119 | Cursor rules | stylearchgitsecurity+2 | 89/100 | 3 days ago | |
| nerds-odd-e/doughnut.cursor/rules/frontend-testing.mdc · 49 | Cursor rules | buildteststyletesting-strategy+2 | 89/100 | 3 days ago | |
| danielvm-git/bigpowers.cursor/rules/organize-workspace.mdc · 119 | Cursor rules | buildstylegitdeployment+2 | 89/100 | 3 days ago |
