Cursor rule
.cursor/rules/pytest-tests.mdcPytest Tests
Cursor rules
Quality
61/100
Scores the file, not the repository.Length
356 words
3 headings · 1 code blocksRepository
13
— · pushed 33 days agoLast changed
3 days ago
First indexed 3 days ago.123456## Pytest Tests789- Look first to `app.factories.*` instead of `app.models.*` to generate any required database state10 - For example, to create and persist a `Distribution` record `DistributionFactory.save()`11 - If a factory doesn't exist for the model you are working with, create one.12 - You can customize one or more params in a factory using `DistributionFactory.save(host="custom_host.com)`13- Use `faker` factory to generate emails, etc.14- Do not mock or patch unless I instruct you to. Test as much of the application stack as possible in each test.15- If you get lazy attribute errors, or need a database session to share across logic, use the `db_session` fixture to fix the issue.16 - Note that when writing route tests a `db_session` is not needed for the logic inside of the route.17- When testing Stripe, use the sandbox API. Never mock out Stripe interactions unless explicitly told to.18- Omit obvious docstrs and comments. Add comments for non-obvious but easy-to-miss lines that are key to what the test is checking.19- If a docstring needs formatting, use markdown. Use Google Style.2021### Example Test2223Below is an example test, you'll notice the following:2425- Docstr is omitted since the purpose of the test is obvious26- Comment about the `county` is added since it's the main point of the test27- Newline between test setup, functionality under test, and assertions against result28- `api_app_url_path_for` helper is used instead of hardcoded routes2930```python31from app.generated.fastapi_typed_routes import api_app_url_path_for32import json3334def test_calculate_quote_unknown_county(client):35 payload = {36 "subscriber": {"age": 35, "gender": "M"},37 # fake county to ensure error is thrown38 "county": "NotACounty",39 }4041 response = client.post(42 api_app_url_path_for("composite_quote"),43 json=payload,44 )4546 assert_status(response, status.HTTP_422_UNPROCESSABLE_CONTENT)47```4849### File Structure5051* If there's more than a handful of tests in a folder, you should probably create subfolders.52* File name should be related to the file or primary class / functionality the test is covering. Do not add a component to the test name that exists in the test file path.53 * Example: `app/routes/unauthenticated/quote.py` should be `tests/routes/unauthenticated/quote_test.py`54* `tests/routes/{unauthenticated,authenticated}` and a handful of top-level test files for fastapi API route testing.55* `tests/integration/` for browser tests56
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-integration-tests.mdc · 13 | Cursor rules | teststyletesting-strategy | 73/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-integration-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 |
