PromptTesting and QAOpen
Pytest taste
Pytest taste of a Python developer who wants fast, honest test suites - Use plain assert statements and let pytest's assertion rewriting explain failures instead of unittest-style assert methods. Confidence: 0.95 - Keep tests in a top-level tests/ directory that mirrors the package layout, w
Front matter
name: Pytest taste
description: # Pytest taste of a Python developer who wants fast, honest test suites - Use plain `assert` statements and let pytest's assertion rewriting explain failures instead of `unittest`-style assert methods. Confidence: 0.95 - Keep tests in a top-level `tests/` directory that mirrors the package layout, w
kind: Prompt
audience: DevelopersPytest taste
Pytest taste of a Python developer who wants fast, honest test suites
- Use plain
assertstatements and let pytest's assertion rewriting explain failures instead ofunittest-style assert methods. Confidence: 0.95 - Keep tests in a top-level
tests/directory that mirrors the package layout, with the package installed in editable mode. Confidence: 0.85 - Configure pytest in
pyproject.tomlunder[tool.pytest.ini_options]rather than a separatepytest.iniorsetup.cfg. Confidence: 0.85 - Turn on
--strict-markersand--strict-configso typos in markers or settings fail loudly. Confidence: 0.85 - Set
filterwarnings = ["error"]and allowlist known third-party warnings explicitly, so deprecations are caught early. Confidence: 0.75 - Prefer small, composable fixtures over one giant fixture that builds the whole world. Confidence: 0.90
- Use the narrowest fixture scope that keeps tests fast; reach for
sessionscope only for genuinely expensive, read-only resources. Confidence: 0.80 - Put shared fixtures in the nearest
conftest.py, not one root conftest that every test imports implicitly. Confidence: 0.75 - Use
@pytest.mark.parametrizewith readableidsinstead of loops inside a single test. Confidence: 0.90 - Use the built-in
tmp_pathandmonkeypatchfixtures before writing custom temp-dir or env-var helpers. Confidence: 0.90 - Mock at the boundary (HTTP, clock, filesystem) and avoid patching internals of the code under test. Confidence: 0.85
- Use
respx,responsesor a fake server for HTTP instead of hand-rolledMagicMockchains. Confidence: 0.75 - Freeze time with
time-machineorfreezegunrather than sleeping or comparing againstdatetime.now(). Confidence: 0.80 - Assert on exceptions with
pytest.raises(..., match=...)so the message is checked, not just the type. Confidence: 0.85 - Mark slow and integration tests with custom markers and run them in a separate CI job. Confidence: 0.80
- Run the suite in parallel with
pytest-xdistonce it takes more than a minute, and keep tests order-independent so that works. Confidence: 0.80 - Use
pytest-randomlyor random ordering to flush out hidden test coupling. Confidence: 0.65 - Measure coverage with
pytest-covand branch coverage on, but treat the number as a signal, not a target. Confidence: 0.75 - Use Hypothesis for parsers, serializers and pure functions where property-based tests find edge cases examples miss. Confidence: 0.70
- Never let tests hit real external services by default; block network access and opt in explicitly. Confidence: 0.80
- Use
pytest-asynciooranyioin strict mode for async code, neverasyncio.runinside tests. Confidence: 0.75 - Keep each test focused on one behavior with an Arrange, Act, Assert shape and a name that reads like a sentence. Confidence: 0.85
Contributor: f
Source: https://github.com/f/prompts.chat/blob/main/prompts/02993.md
Author: f, prompts.chat prompt library. License: CC0-1.0.
Shown here with formatting for the web. Keep the author and license notice when you reuse it.
Related entries
There are more like this in the members library
The Business prompt library holds 3,008 entries. Members can search all of them by meaning and read every one in full.