pytest-what-to-test-and-mocking

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

Testing rules for Python projects that use pytest. They specify which external calls to replace with test doubles and which shared test fixtures to reuse.

In plain words
What is it for?
Use them when deciding what to test and how to mock APIs with pytest-mock, monkeypatch, and conftest.py fixtures.
Why use it?
They keep tests focused on the project's own behavior and avoid real external API calls during normal test runs.

Cursor rule for Cursor

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.

agentmods
npx agentmods add rules/technickai/ai-coding-config/pytest-what-to-test-and-mocking
Clone the repo
git clone --depth 1 https://github.com/TechNickAI/ai-coding-config

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/ai-coding-config/pytest-what-to-test-and-mocking.svg)](https://agentmods.dev/rules/technickai/ai-coding-config/pytest-what-to-test-and-mocking)
Your own site
<a href="https://agentmods.dev/rules/technickai/ai-coding-config/pytest-what-to-test-and-mocking"><img src="https://agentmods.dev/badge/rules/technickai/ai-coding-config/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. Scan, not verified.
Origin 100% copy Near-identical to another mod 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 $0.00003 $0.01047
Opus 5 $0.00002 $0.00524
Sonnet 5 $0.00001 $0.00209
Haiku 4.5 $0.00000 $0.00105

Measured 5d ago against content hash 691f7154c5e2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 5d 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

This is a copy

100% identical to pytest-what-to-test-and-mocking — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.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. 5d 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/ai-coding-config (24 stars, last pushed 2mo 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). It is 100% identical to pytest-what-to-test-and-mocking, differing in 0 lines, and is treated as a copy.