pytest-what-to-test-and-mocking

pytest-what-to-test-and-mocking is a cursor rule for Cursor from TechNickAI/claude_telemetry. It costs 3 tokens per session (1,047 once invoked), scanned A, original, MIT.

Testing guidance for Python projects that use pytest, a framework for writing and running tests. It explains what application logic to test and how to replace external services with controlled test doubles.

In plain words
What is it for?
Use it when writing tests for business rules, error handling, state changes, and calls to services such as Stripe.
Why use it?
It helps keep tests focused on your own code instead of re-testing libraries, while avoiding real external API calls during normal tests. It also sets consistent rules for fixtures and mocking.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when writing tests for business rules, error handling, state changes, and calls to services such as Stripe.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/technickai/claude_telemetry/pytest-what-to-test-and-mocking
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/TechNickAI/claude_telemetry

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pytest-what-to-test-and-mocking

README.md
[![agentmods](https://agentmods.dev/badge/rules/technickai/claude_telemetry/pytest-what-to-test-and-mocking.svg)](https://agentmods.dev/rules/technickai/claude_telemetry/pytest-what-to-test-and-mocking)
Your own site
<a href="https://agentmods.dev/rules/technickai/claude_telemetry/pytest-what-to-test-and-mocking"><img src="https://agentmods.dev/badge/rules/technickai/claude_telemetry/pytest-what-to-test-and-mocking.svg" alt="Measured on agentmods" height="20"></a>
Per session 3 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,047 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00003 $0.01047
Opus 5 $0.00002 $0.00524
Sonnet 5 $0.00001 $0.00209
Haiku 4.5 $0.00000 $0.00105

Measured 8d ago against content hash 691f7154c5e2, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

pytest-what-to-test-and-mocking scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

mocker.patch("requests.get", return_value=mock_response)
Origin

Copies of this mod

1 near-identical copy found in the catalogue:

.cursor/rules/python/pytest-what-to-test-and-mocking.mdc · 136 lines

How it starts

The opening of the file, as written. The whole thing — 136 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Pytest: What to Test and Mocking

Core Requirements

We mock external API calls (mark live tests with @pytest.mark.flaky()). We reuse fixtures from conftest.py. We always use pytest as testing framework - never import unittest. We use pytest-mock (mocker fixture) and monkeypatch for mocking, not unittest.mock.

What to Test

Test your business logic, not the libraries you depend on.

Test Your Business Logic

def test_calculates_discount_correctly():
    """Test our custom discount calculation"""
    order = Order(subtotal=Decimal("100.00"))
    discount = calculate_discount(order, coupon_code="SAVE20")
    assert discount == Decimal("20.00")

def test_handles_invalid_coupon_gracefully():
    """Test our error handling for invalid coupons"""
    order = Order(subtotal=Decimal("100.00"))
    discount = calculate_discount(order, coupon_code="INVALID")
    assert discount == Decimal("0.00")

def test_order_state_transitions():
    """Test our state machine logic"""
    order = Order(status="pending")
    order.mark_paid()
    assert order.status == "paid"
    assert order.paid_at is not None

Test Integration Points

def test_sends_correct_parameters_to_stripe(mocker):
    """Test how we call Stripe API"""
    mock_stripe = mocker.patch("stripe.Charge.create")
    process_payment(order_id="123", amount=Decimal("50.00"))
    mock_stripe.assert_called_once_with(
        amount=5000,  # cents
        currency="usd",
        source="tok_visa"
    )

def test_processes_stripe_response_correctly():
    """Test how we transform Stripe data"""
    stripe_response = {"id": "ch_123", "status": "succeeded"}
    payment = Payment.from_stripe_response(stripe_response)
    assert payment.external_id == "ch_123"
    assert payment.status == "completed"

Skip Library Testing

We don't test that Pydantic validates, Django filters work, or httpx makes requests. These libraries test themselves. We focus on our logic that uses these tools.

Read the full file on GitHub · 136 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 136 lines · 3 tokens per session scan A 691f7154c5e2

Subscribe to this mod's changes

pytest-what-to-test-and-mocking is a cursor rule published in the GitHub repository TechNickAI/claude_telemetry (31 stars, last pushed 10mo ago), licensed MIT. It adds 3 tokens to every session and 1,047 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.