← ClaudeAtlas

cast-pytest-best-practiceslisted

Apply pytest best practices when writing test files. Use when creating test_*.py files, writing test classes and methods, or ensuring test quality and coverage.
sridherj/diecast · ★ 3 · AI & Automation · score 72
Install: claude install-skill sridherj/diecast
# PytestBestPractices Skill Apply these pytest best practices when writing or reviewing tests. ## Reference Files - `./reference_code/.cursor/rules/pytest.mdc` - `./reference_code/conftest.py` - `./reference_code/tests/projects/` (example tests) ## Naming Conventions | Type | Prefix | Example | |------|--------|---------| | Mock objects | `mock_` | `mock_service`, `mock_repository` | | Fake objects | `fake_` | `fake_client`, `fake_api` | | Test data | `test_` | `test_project_id`, `test_tenant_id` | | Expected values | `expected_` | `expected_count`, `expected_name` | | Actual results | `actual_` | `actual_projects`, `actual_result` | ## Test Structure ### Arrange-Act-Assert Pattern ```python def test_something(self, repository, test_tenant_id): # Arrange - set up test data and expectations expected_count = 5 expected_status = ProjectStatus.ACTIVE # Act - call the method under test actual_results = repository.list_with_filters( tenant_id=test_tenant_id, status=[expected_status] ) # Assert - verify results assert len(actual_results) == expected_count assert all(r.status == expected_status for r in actual_results) ``` ## Key Rules ### Use Enums, Not Strings ```python # WRONG status='ACTIVE' # CORRECT status=ProjectStatus.ACTIVE ``` ### Use DateTimeComparator for Timestamps SQLite has timezone issues and JSON responses may serialize datetimes in local timezone - use the helper from conftest: ```python # Repository te