Full standards in pytest.md. Always-on summary:
File and function naming:
- Files:
test_<module>.py(prefix, not suffix) — pytest discovers these automatically - Functions:
def test_<behaviour>()— describe the behaviour, not the method - Classes:
class TestUserService:— group related tests; no__init__method
Fixtures:
- Declare with
@pytest.fixturedecorator inconftest.py— pytest injects them automatically by parameter name - Use the narrowest scope needed:
function(default) →class→module→session - Yield fixtures for setup/teardown:
yieldprovides the value; cleanup runs after
Parametrize:
@pytest.mark.parametrizefor testing multiple inputs — never copy-paste tests- Use
ids=for readable test names in the output
Assertions:
- Plain
assertstatements — pytest rewrites them for detailed output; e.g.,assert response.status_code == 200 pytest.raises(ExcType)for exception testing — use as context managerpytest.approx()for floating-point comparisons
Output capture:
- Use the
capsysfixture to capture and assert on stdout/stderr — never write raw stdout in tests
Never:
unittest.TestCasestyle in new pytest code — use plain functions and fixtures- Raw stdout debugging — use
pytest -sflag or proper logging - Skip tests without a reason:
@pytest.mark.skip(reason='...')required
Related skills: backend/python-fastapi (pytest-asyncio, TestClient), database/sqlalchemy (session fixture patterns)
Source: manikumarkv/devrunway-claude-plugin — distributed by TomeVault.