Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

🤖 Artificial Intelligence
☁️ Cloud and Infrastructure
💾 Data and Databases
💼 Professional Skills
🎯 Programming and Development
🔒 Security and Networking
📚 Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 0
0/5 XP
GitHub
© 2026 CheatGrid™. All rights reserved.
Privacy PolicyTerms of UseAboutContact

pytest Cheat Sheet

pytest Cheat Sheet

Back to Developer Tools
Updated 2026-04-29
Next Topic: RStudio Cheat Sheet

pytest is Python's leading testing framework, built on plain assert statements with automatic introspection that shows exactly what failed and why. Unlike unittest's verbose class-based approach, pytest uses fixture dependency injection for clean test setup and a rich plugin ecosystem with 900+ extensions. The framework's key innovation is making the common case trivial—write def test_something(): assert result == expected—while providing advanced features like parametrization, markers, subtests, and parallel execution when complexity demands them. With pytest 9.0 (released 2025), the framework gained native subtests support, a new pytest.toml config file, and a comprehensive strict mode.

What This Cheat Sheet Covers

This topic spans 21 focused tables and 180 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1: Core pytest ConceptsTable 2: Assertions and ComparisonsTable 3: Fixtures - Setup and TeardownTable 4: conftest.py and Fixture SharingTable 5: ParametrizationTable 6: MarkersTable 7: Built-in FixturesTable 8: Monkeypatch OperationsTable 9: Test Discovery and CollectionTable 10: Output and ReportingTable 11: Configuration FilesTable 12: Configuration OptionsTable 13: Coverage with pytest-covTable 14: Popular pytest PluginsTable 15: Parallel Execution (pytest-xdist)Table 16: Warnings ManagementTable 17: Subtests (pytest 9.0)Table 18: Hooks and PluginsTable 19: Doctest IntegrationTable 20: Testing StrategiesTable 21: Advanced Fixture Patterns

Table 1: Core pytest Concepts

ConceptExampleDescription
test function
def test_addition():
assert 1 + 1 == 2
• Test functions must start with test_
• automatic discovery finds and executes them
• no classes or inheritance required.
simple assert
assert value == 42
• Plain Python assert with automatic introspection—pytest rewrites assertions to show intermediate values on failure
• no special methods needed.
test file naming
test_*.py or *_test.py
Files must match these patterns for discovery—test_ prefix or _test.py suffix trigger collection.
test class naming
class TestUserAuth:
• Optional classes group related tests—must start with Test (no __init__)
• methods also need test_ prefix.

More in Developer Tools

  • PyCharm Cheat Sheet
  • RStudio Cheat Sheet
  • AI-LLM Code Generation Cheat Sheet
  • Docker Desktop for Developers Cheat Sheet
  • Jupyter Notebooks Cheat Sheet
  • Sublime Text Cheat Sheet
View all 55 topics in Developer Tools