Covers TDD methodology (red-green-refactor cycle), parametrization, fixtures with multiple scopes, and mocking patterns for unit and integration testing
Includes pytest fundamentals: assertions, markers for test selection, exception testing, and async test support with pytest-asyncio
Provides practical patterns for testing APIs, databases, file operations, and class methods with real cod
Confirm successful installation by checking the skill directory location:
.cursor/skills/python-testing
Restart Cursor to activate python-testing. Access via /python-testing in your agent's command palette.
โ
Security Notice
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Comprehensive testing strategies for Python applications using pytest, TDD methodology, and best practices.
When to Activate
Writing new Python code (follow TDD: red, green, refactor)
Designing test suites for Python projects
Reviewing Python test coverage
Setting up testing infrastructure
Core Testing Philosophy
Test-Driven Development (TDD)
Always follow the TDD cycle:
RED: Write a failing test for the desired behavior
GREEN: Write minimal code to make the test pass
REFACTOR: Improve code while keeping tests green
# Step 1: Write failing test (RED)deftest_add_numbers(): result = add(2,3)assert result ==5# Step 2: Write minimal implementation (GREEN)defadd(a, b):return a + b
# Step 3: Refactor if needed (REFACTOR)
import pytest
deftest_addition():"""Test basic addition."""assert2+2==4deftest_string_uppercase():"""Test string uppercasing.""" text ="hello"assert text.upper()=="HELLO"deftest_list_append():"""Test list append.""" items =[1,2,3] items.append(4)assert4in items
assertlen(items)==4
Assertions
# Equalityassert result == expected
# Inequalityassert result != unexpected
# Truthinessassert result # Truthyassertnot result # Falsyassert result isTrue# Exactly Trueassert result isFalse# Exactly Falseassert result isNone# Exactly None# Membershipassert item in collection
assert item notin collection
# Comparisonsassert result >0assert0<= result <=100# Type checkingassertisinstance(result,str)# Exception testing (preferred approach)with pytest.raises(ValueError):raise ValueError("error message")# Check exception messagewith pytest.raises(ValueError,match="invalid input"):raise ValueError("invalid input provided")# Check exception attributeswith pytest.raises(ValueError)as exc_info:raise ValueError("error message")assertstr(exc_info.value)=="error message"
Fixtures
Basic Fixture Usage
import pytest
@pytest.fixturedefsample_data():"""Fixture providing sample data."""return{"name":"Alice","age":30}deftest_sample_data(sample_data):"""Test using the fixture."""assert sample_data["name"]=="Alice"assert sample_data["age"]==30
Fixture with Setup/Teardown
@pytest.fixturedefdatabase():"""Fixture with setup and teardown."""# Setup db = Database(":memory:") db.create_tables() db.insert_test_data()yield db # Provide to test# Teardown db.close()deftest_database_query(database):"""Test database operations.""" result = database.query("SELECT * FROM users")assertlen(result)>0
Fixture Scopes
# Function scope (default) - runs for each test@pytest.fixturedeftemp_file():withopen("temp.txt","w")as f:yield f
os.remove("temp.txt")# Module scope - runs once per module@pytest.fixture(scope="module")defmodule_db(): db = Database(":memory:") db.create_tables()yield db
db.close()# Session scope - runs once per test session@pytest.fixture(scope="session")defshared_resource(): resource = ExpensiveResource()yield resource
resource.cleanup()
Fixture with Parameters
@pytest.fixture(params=[1,2,3])defnumber(request):"""Parameterized fixture."""return request.param
deftest_numbers(number):"""Test runs 3 times, once for each parameter."""assert number >0
โบClaude Desktop or compatible AI client with skill support
โบClear understanding of task or problem to solve
โบWillingness to iterate and refine outputs
Time Estimate
15-45 minutes depending on use case complexity
Steps
1Install skill using provided installation command
2Test with simple use case relevant to your work
3Evaluate output quality and relevance
4Iterate on prompts to improve results
5Integrate into regular workflow if valuable
Common Pitfalls
โ Expecting perfect results without iteration
โ Not providing enough context in prompts
โ Using skill for tasks outside its intended scope
โ Accepting outputs without review and validation
Best Practices
โ Do
+Start with clear, specific prompts
+Provide relevant context and constraints
+Review and refine all outputs before using
+Iterate to improve output quality
+Document successful prompt patterns
โ Don't
โDon't use without understanding skill limitations
โDon't skip validation of outputs
โDon't share sensitive information in prompts
โDon't expect skill to replace human judgment
๐ก Pro Tips
โ Be specific about desired format and style
โ Ask for multiple options to choose from
โ Request explanations to understand reasoning
โ Combine AI efficiency with human expertise
When to Use This
โ Use when
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
โ Avoid when
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
Learning Path
1Familiarize yourself with skill capabilities and limitations
2Start with low-risk, non-critical tasks
3Progress to more complex and valuable use cases
4Build expertise through regular use and experimentation