- Home
- Skills
- Testing & Debugging
- Python Pytest Pro — Fixtures & Parametrize
Python Pytest Pro — Fixtures & Parametrize
Pytest-depth tests: fixtures, parametrize, monkeypatch — confirm before production edits.
$24
Works with the AI Agents you already use
Python Pytest Pro — Fixtures & Parametrize
Example session with this skill installed
python-pytest-pro: write tests for my user authentication logic in auth.py. I need to test successful login and failed attempts with different status codes.
- Read your context and instructions
- Compiled the python pytest pro
I have analyzed your auth.py and detected a standard tests/ directory structure. I will now create a test suite using pytest.mark.parametrize for the failure cases and a fixture for the API client session.
Test Suite Implementation
import pytest
from my_app.auth import AuthService
@pytest.fixture
def auth_service(monkeypatch):
"""Provides a service instance with mocked network calls."""
service = AuthService()
# Mocking actual network request to avoid side effects
monkeypatch.setattr(service, "_call_provider", lambda x: {"status": 200})
return service
@pytest.mark.parametrize("credentials, expected_status", [
({"user": "admin", "pass": "wrong"}, 401),
({"user": "nonexistent", "pass": "pass"}, 404),
({"user": "", "pass": ""}, 400),
])
def test_login_failures(auth_service, credentials, expected_status):
"""Verifies authentication failures return correct status codes."""
response = auth_service.login(credentials["user"], credentials["pass"])
assert response.status_code == expected_status
def test_login_success(auth_service, monkeypatch):
"""Verifies successful authentication flow."""
monkeypatch.setattr(auth_service, "_call_provider", lambda x: {"status": 200, "token": "abc"})
response = auth_service.login("valid_user", "correct_pass")
assert response.status_code == 200
assert "token" in response.data
Next steps
- Run
pytest tests/test_auth.py -qto verify the new suite. - Review the
monkeypatchlogic to ensure it aligns with your auth provider's response schema. - Approve production edits to
auth.pyif logic adjustments are needed for the 404 case.
Connects securely to your tools. The creator never sees your data.
About this skill
Writing tests that actually catch bugs requires more than just calling functions. Generic AI prompts often miss essential pytest idioms, resulting in brittle suites or skipped edge cases. This skill enforces professional testing standards by leveraging advanced pytest features like fixtures, parametrization, and monkeypatching.
What it does
- Advanced fixtures handles setup and teardown logic using idiomatic shared fixtures to keep tests DRY.
- Data parametrization generates test matrices to cover multiple input scenarios without duplicating code.
- Dependency isolation uses monkeypatch to mock external calls and network traffic, ensuring deterministic results.
- Structural detection identifies existing
pytest.ini,pyproject.toml, ortests/layouts to maintain project consistency. - TDD workflow follows a strict red-green-refactor cycle, identifying failures before applying production fixes.
How it works
- Detect environment by scanning for configuration files and async plugins.
- Define failures by naming the failing test and assertion, then listing required production edits for approval.
- Implement tests by placing code in conventional paths and running targeted pytest commands.
- Refactor suite by consolidating shared fixtures and expanding parametrization.
Frameworks & tools
This skill is designed for Python projects utilizing pytest. It supports projects with pytest-asyncio and standard configuration files like pyproject.toml or pytest.ini.
Why this beats prompting it yourself
Standard prompts often produce flat, repetitive test scripts that ignore established project structures. This skill enforces the use of specific pytest idioms and requires explicit confirmation before touching production code, preventing accidental regressions.
Use cases
- Add comprehensive test coverage to a legacy Python module.
- Fix broken test suites by identifying the specific assertion failure.
- Mock external API calls using monkeypatch to enable offline testing.
- Refactor repetitive tests into clean, parametrized matrices.
Known limitations
Requires an existing Python environment with pytest installed. Does not generate arbitrary coverage percentage reports.
Requires pytest to be installed in the environment. Will not delete or skip tests without explicit user confirmation. Does not support automated coverage percentage generation.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 24 days ago
Requires