{"slug":"python-testing","title":"python-testing","summary":"Python testing strategies using pytest, TDD methodology, fixtures, mocking, parametrization, and coverage requirements. Use when writing pytest tests — fixtures, mocks, parametrization, or coverage.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-02T16:53:45.893224Z","repo":{"url":"https://github.com/beginwithu/agent-skills","stars":11,"forks":2,"license":"MIT","updatedAt":"2026-12-02T16:37:11Z"},"bodyHtml":"<hr>\n<h2>name: python-testing\ndescription: Python testing strategies using pytest, TDD methodology, fixtures, mocking, parametrization, and coverage requirements. Use when writing pytest tests — fixtures, mocks, parametrization, or coverage.\nmetadata:\norigin: ECC</h2>\n<h1>Python Testing Patterns</h1>\n<p>Comprehensive testing strategies for Python applications using pytest, TDD methodology, and best practices.</p>\n<h2>When to Activate</h2>\n<ul>\n<li>Writing new Python code (follow TDD: red, green, refactor)</li>\n<li>Designing test suites for Python projects</li>\n<li>Reviewing Python test coverage</li>\n<li>Setting up testing infrastructure</li>\n</ul>\n<h2>Core Testing Philosophy</h2>\n<h3>Test-Driven Development (TDD)</h3>\n<p>Always follow the TDD cycle:</p>\n<ol>\n<li><strong>RED</strong>: Write a failing test for the desired behavior</li>\n<li><strong>GREEN</strong>: Write minimal code to make the test pass</li>\n<li><strong>REFACTOR</strong>: Improve code while keeping tests green</li>\n</ol>\n<pre><code># Step 1: Write failing test (RED)\ndef test_add_numbers():\n    result = add(2, 3)\n    assert result == 5\n\n# Step 2: Write minimal implementation (GREEN)\ndef add(a, b):\n    return a + b\n\n# Step 3: Refactor if needed (REFACTOR)\n</code></pre>\n<h3>Coverage Requirements</h3>\n<ul>\n<li><strong>Target</strong>: 80%+ code coverage</li>\n<li><strong>Critical paths</strong>: 100% coverage required</li>\n<li>Use <code>pytest --cov</code> to measure coverage</li>\n</ul>\n<pre><code>pytest --cov=mypackage --cov-report=term-missing --cov-report=html\n</code></pre>\n<h2>pytest Fundamentals</h2>\n<h3>Basic Test Structure</h3>\n<pre><code>import pytest\n\ndef test_addition():\n    \"\"\"Test basic addition.\"\"\"\n    assert 2 + 2 == 4\n\ndef test_string_uppercase():\n    \"\"\"Test string uppercasing.\"\"\"\n    text = \"hello\"\n    assert text.upper() == \"HELLO\"\n\ndef test_list_append():\n    \"\"\"Test list append.\"\"\"\n    items = [1, 2, 3]\n    items.append(4)\n    assert 4 in items\n    assert len(items) == 4\n</code></pre>\n<h3>Assertions</h3>\n<pre><code># Equality\nassert result == expected\n\n# Inequality\nassert result != unexpected\n\n# Truthiness\nassert result  # Truthy\nassert not result  # Falsy\nassert result is True  # Exactly True\nassert result is False  # Exactly False\nassert result is None  # Exactly None\n\n# Membership\nassert item in collection\nassert item not in collection\n\n# Comparisons\nassert result &gt; 0\nassert 0 &lt;= result &lt;= 100\n\n# Type checking\nassert isinstance(result, str)\n\n# Exception testing (preferred approach)\nwith pytest.raises(ValueError):\n    raise ValueError(\"error message\")\n\n# Check exception message\nwith pytest.raises(ValueError, match=\"invalid input\"):\n    raise ValueError(\"invalid input provided\")\n\n# Check exception attributes\nwith pytest.raises(ValueError) as exc_info:\n    raise ValueError(\"error message\")\nassert str(exc_info.value) == \"error message\"\n</code></pre>\n<h2>Fixtures</h2>\n<h3>Basic Fixture Usage</h3>\n<pre><code>import pytest\n\n@pytest.fixture\ndef sample_data():\n    \"\"\"Fixture providing sample data.\"\"\"\n    return {\"name\": \"Alice\", \"age\": 30}\n\ndef test_sample_data(sample_data):\n    \"\"\"Test using the fixture.\"\"\"\n    assert sample_data[\"name\"] == \"Alice\"\n    assert sample_data[\"age\"] == 30\n</code></pre>\n<h3>Fixture with Setup/Teardown</h3>\n<pre><code>@pytest.fixture\ndef database():\n    \"\"\"Fixture with setup and teardown.\"\"\"\n    # Setup\n    db = Database(\":memory:\")\n    db.create_tables()\n    db.insert_test_data()\n\n    yield db  # Provide to test\n\n    # Teardown\n    db.close()\n\ndef test_database_query(database):\n    \"\"\"Test database operations.\"\"\"\n    result = database.query(\"SELECT * FROM users\")\n    assert len(result) &gt; 0\n</code></pre>\n<h3>Fixture Scopes</h3>\n<pre><code># Function scope (default) - runs for each test\n@pytest.fixture\ndef temp_file():\n    with open(\"temp.txt\", \"w\") as f:\n        yield f\n    os.remove(\"temp.txt\")\n\n# Module scope - runs once per module\n@pytest.fixture(scope=\"module\")\ndef module_db():\n    db = Database(\":memory:\")\n    db.create_tables()\n    yield db\n    db.close()\n\n# Session scope - runs once per test session\n@pytest.fixture(scope=\"session\")\ndef shared_resource():\n    resource = ExpensiveResource()\n    yield resource\n    resource.cleanup()\n</code></pre>\n<h3>Fixture with Parameters</h3>\n<pre><code>@pytest.fixture(params=[1, 2, 3])\ndef number(request):\n    \"\"\"Parameterized fixture.\"\"\"\n    return request.param\n\ndef test_numbers(number):\n    \"\"\"Test runs 3 times, once for each parameter.\"\"\"\n    assert number &gt; 0\n</code></pre>\n<h3>Using Multiple Fixtures</h3>\n<pre><code>@pytest.fixture\ndef user():\n    return User(id=1, name=\"Alice\")\n\n@pytest.fixture\ndef admin():\n    return User(id=2, name=\"Admin\", role=\"admin\")\n\ndef test_user_admin_interaction(user, admin):\n    \"\"\"Test using multiple fixtures.\"\"\"\n    assert admin.can_manage(user)\n</code></pre>\n<h3>Autouse Fixtures</h3>\n<pre><code>@pytest.fixture(autouse=True)\ndef reset_config():\n    \"\"\"Automatically runs before every test.\"\"\"\n    Config.reset()\n    yield\n    Config.cleanup()\n\ndef test_without_fixture_call():\n    # reset_config runs automatically\n    assert Config.get_setting(\"debug\") is False\n</code></pre>\n<h3>Conftest.py for Shared Fixtures (Flask)</h3>\n<pre><code># tests/conftest.py\nimport pytest\n\n@pytest.fixture\ndef client():\n    \"\"\"Shared fixture for all tests.\"\"\"\n    app = create_app(testing=True)\n    with app.test_client() as client:\n        yield client\n\n@pytest.fixture\ndef auth_headers(client):\n    \"\"\"Generate auth headers for API testing.\"\"\"\n    response = client.post(\"/api/login\", json={\n        \"username\": \"test\",\n        \"password\": \"test\"\n    })\n    token = response.json[\"token\"]\n    return {\"Authorization\": f\"Bearer {token}\"}\n</code></pre>\n<h2>Parametrization</h2>\n<h3>Basic Parametrization</h3>\n<pre><code>@pytest.mark.parametrize(\"input,expected\", [\n    (\"hello\", \"HELLO\"),\n    (\"world\", \"WORLD\"),\n    (\"PyThOn\", \"PYTHON\"),\n])\ndef test_uppercase(input, expected):\n    \"\"\"Test runs 3 times with different inputs.\"\"\"\n    assert input.upper() == expected\n</code></pre>\n<h3>Multiple Parameters</h3>\n<pre><code>@pytest.mark.parametrize(\"a,b,expected\", [\n    (2, 3, 5),\n    (0, 0, 0),\n    (-1, 1, 0),\n    (100, 200, 300),\n])\ndef test_add(a, b, expected):\n    \"\"\"Test addition with multiple inputs.\"\"\"\n    assert add(a, b) == expected\n</code></pre>\n<h3>Parametrize with IDs</h3>\n<pre><code>@pytest.mark.parametrize(\"input,expected\", [\n    (\"valid@email.com\", True),\n    (\"invalid\", False),\n    (\"@no-domain.com\", False),\n], ids=[\"valid-email\", \"missing-at\", \"missing-domain\"])\ndef test_email_validation(input, expected):\n    \"\"\"Test email validation with readable test IDs.\"\"\"\n    assert is_valid_email(input) is expected\n</code></pre>\n<h3>Parametrized Fixtures</h3>\n<pre><code>@pytest.fixture(params=[\"sqlite\", \"postgresql\", \"mysql\"])\ndef db(request):\n    \"\"\"Test against multiple database backends.\"\"\"\n    if request.param == \"sqlite\":\n        return Database(\":memory:\")\n    elif request.param == \"postgresql\":\n        return Database(\"postgresql://localhost/test\")\n    elif request.param == \"mysql\":\n        return Database(\"mysql://localhost/test\")\n\ndef test_database_operations(db):\n    \"\"\"Test runs 3 times, once for each database.\"\"\"\n    result = db.query(\"SELECT 1\")\n    assert result is not None\n</code></pre>\n<h2>Markers and Test Selection</h2>\n<h3>Custom Markers</h3>\n<pre><code># Mark slow tests\n@pytest.mark.slow\ndef test_slow_operation():\n    time.sleep(5)\n\n# Mark integration tests\n@pytest.mark.integration\ndef test_api_integration():\n    response = requests.get(\"https://api.example.com\")\n    assert response.status_code == 200\n\n# Mark unit tests\n@pytest.mark.unit\ndef test_unit_logic():\n    assert calculate(2, 3) == 5\n</code></pre>\n<h3>Run Specific Tests</h3>\n<pre><code># Run only fast tests\npytest -m \"not slow\"\n\n# Run only integration tests\npytest -m integration\n\n# Run integration or slow tests\npytest -m \"integration or slow\"\n\n# Run tests marked as unit but not slow\npytest -m \"unit and not slow\"\n</code></pre>\n<h3>Configure Markers in pytest.ini</h3>\n<pre><code>[pytest]\nmarkers =\n    slow: marks tests as slow\n    integration: marks tests as integration tests\n    unit: marks tests as unit tests\n    django: marks tests as requiring Django\n</code></pre>\n<h2>Mocking and Patching</h2>\n<h3>Mocking Functions</h3>\n<pre><code>from unittest.mock import patch, Mock\n\n@patch(\"mypackage.external_api_call\")\ndef test_with_mock(api_call_mock):\n    \"\"\"Test with mocked external API.\"\"\"\n    api_call_mock.return_value = {\"status\": \"success\"}\n\n    result = my_function()\n\n    api_call_mock.assert_called_once()\n    assert result[\"status\"] == \"success\"\n</code></pre>\n<h3>Mocking Return Values</h3>\n<pre><code>@patch(\"mypackage.Database.connect\")\ndef test_database_connection(connect_mock):\n    \"\"\"Test with mocked database connection.\"\"\"\n    connect_mock.return_value = MockConnection()\n\n    db = Database()\n    db.connect()\n\n    connect_mock.assert_called_once_with(\"localhost\")\n</code></pre>\n<h3>Mocking Exceptions</h3>\n<pre><code>@patch(\"mypackage.api_call\")\ndef test_api_error_handling(api_call_mock):\n    \"\"\"Test error handling with mocked exception.\"\"\"\n    api_call_mock.side_effect = ConnectionError(\"Network error\")\n\n    with pytest.raises(ConnectionError):\n        api_call()\n\n    api_call_mock.assert_called_once()\n</code></pre>\n<h3>Mocking Context Managers</h3>\n<pre><code>@patch(\"builtins.open\", new_callable=mock_open)\ndef test_file_reading(mock_file):\n    \"\"\"Test file reading with mocked open.\"\"\"\n    mock_file.return_value.read.return_value = \"file content\"\n\n    result = read_file(\"test.txt\")\n\n    mock_file.assert_called_once_with(\"test.txt\", \"r\")\n    assert result == \"file content\"\n</code></pre>\n<h3>Using Autospec</h3>\n<pre><code>@patch(\"mypackage.DBConnection\", autospec=True)\ndef test_autospec(db_mock):\n    \"\"\"Test with autospec to catch API misuse.\"\"\"\n    db = db_mock.return_value\n    db.query(\"SELECT * FROM users\")\n\n    # This would fail if DBConnection doesn't have query method\n    db_mock.assert_called_once()\n</code></pre>\n<h3>Mock Class Instances</h3>\n<pre><code>class TestUserService:\n    @patch(\"mypackage.UserRepository\")\n    def test_create_user(self, repo_mock):\n        \"\"\"Test user creation with mocked repository.\"\"\"\n        repo_mock.return_value.save.return_value = User(id=1, name=\"Alice\")\n\n        service = UserService(repo_mock.return_value)\n        user = service.create_user(name=\"Alice\")\n\n        assert user.name == \"Alice\"\n        repo_mock.return_value.save.assert_called_once()\n</code></pre>\n<h3>Mock Property</h3>\n<pre><code>@pytest.fixture\ndef mock_config():\n    \"\"\"Create a mock with a property.\"\"\"\n    config = Mock()\n    type(config).debug = PropertyMock(return_value=True)\n    type(config).api_key = PropertyMock(return_value=\"test-key\")\n    return config\n\ndef test_with_mock_config(mock_config):\n    \"\"\"Test with mocked config properties.\"\"\"\n    assert mock_config.debug is True\n    assert mock_config.api_key == \"test-key\"\n</code></pre>\n<h2>Testing Async Code</h2>\n<h3>Async Tests with pytest-asyncio</h3>\n<pre><code>import pytest\n\n@pytest.mark.asyncio\nasync def test_async_function():\n    \"\"\"Test async function.\"\"\"\n    result = await async_add(2, 3)\n    assert result == 5\n\n@pytest.mark.asyncio\nasync def test_async_with_fixture(async_client):\n    \"\"\"Test async with async fixture.\"\"\"\n    response = await async_client.get(\"/api/users\")\n    assert response.status_code == 200\n</code></pre>\n<h3>Async Fixture (FastAPI)</h3>\n<p><code>ASGITransport</code> does not run lifespan events. Install <code>asgi-lifespan</code> and wrap the client in <code>LifespanManager</code> when the app uses startup or shutdown handlers. See <a href=\"https://github.com/fastapi/fastapi/blob/master/docs/en/docs/advanced/async-tests.md\">FastAPI's async testing guidance</a>.</p>\n<pre><code>import pytest\nimport pytest_asyncio\nfrom asgi_lifespan import LifespanManager\nfrom httpx import ASGITransport, AsyncClient\n\n@pytest_asyncio.fixture\nasync def async_client():\n    \"\"\"Async fixture providing async test client with lifespan events.\"\"\"\n    app = create_app()  # Returns a FastAPI application\n    async with LifespanManager(app) as manager:\n        async with AsyncClient(transport=ASGITransport(app=manager.app), base_url=\"http://test\") as client:\n            yield client\n\n@pytest.mark.asyncio\nasync def test_api_endpoint(async_client):\n    \"\"\"Test using async fixture.\"\"\"\n    response = await async_client.get(\"/api/data\")\n    assert response.status_code == 200\n</code></pre>\n<h3>Mocking Async Functions</h3>\n<pre><code>@pytest.mark.asyncio\n@patch(\"mypackage.async_api_call\")\nasync def test_async_mock(api_call_mock):\n    \"\"\"Test async function with mock.\"\"\"\n    api_call_mock.return_value = {\"status\": \"ok\"}\n\n    result = await my_async_function()\n\n    api_call_mock.assert_awaited_once()\n    assert result[\"status\"] == \"ok\"\n</code></pre>\n<h2>Testing Exceptions</h2>\n<h3>Testing Expected Exceptions</h3>\n<pre><code>def test_divide_by_zero():\n    \"\"\"Test that dividing by zero raises ZeroDivisionError.\"\"\"\n    with pytest.raises(ZeroDivisionError):\n        divide(10, 0)\n\ndef test_custom_exception():\n    \"\"\"Test custom exception with message.\"\"\"\n    with pytest.raises(ValueError, match=\"invalid input\"):\n        validate_input(\"invalid\")\n</code></pre>\n<h3>Testing Exception Attributes</h3>\n<pre><code>def test_exception_with_details():\n    \"\"\"Test exception with custom attributes.\"\"\"\n    with pytest.raises(CustomError) as exc_info:\n        raise CustomError(\"error\", code=400)\n\n    assert exc_info.value.code == 400\n    assert \"error\" in str(exc_info.value)\n</code></pre>\n<h2>Testing Side Effects</h2>\n<h3>Testing File Operations</h3>\n<pre><code>import tempfile\nimport os\n\ndef test_file_processing():\n    \"\"\"Test file processing with temp file.\"\"\"\n    with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt') as f:\n        f.write(\"test content\")\n        temp_path = f.name\n\n    try:\n        result = process_file(temp_path)\n        assert result == \"processed: test content\"\n    finally:\n        os.unlink(temp_path)\n</code></pre>\n<h3>Testing with pytest's tmp_path Fixture</h3>\n<pre><code>def test_with_tmp_path(tmp_path):\n    \"\"\"Test using pytest's built-in temp path fixture.\"\"\"\n    test_file = tmp_path / \"test.txt\"\n    test_file.write_text(\"hello world\")\n\n    result = process_file(str(test_file))\n    assert result == \"hello world\"\n    # tmp_path automatically cleaned up\n</code></pre>\n<h3>Testing with tmpdir Fixture</h3>\n<pre><code>def test_with_tmpdir(tmpdir):\n    \"\"\"Test using pytest's tmpdir fixture.\"\"\"\n    test_file = tmpdir.join(\"test.txt\")\n    test_file.write(\"data\")\n\n    result = process_file(str(test_file))\n    assert result == \"data\"\n</code></pre>\n<h2>Test Organization</h2>\n<h3>Directory Structure</h3>\n<pre><code>tests/\n├── conftest.py                 # Shared fixtures\n├── __init__.py\n├── unit/                       # Unit tests\n│   ├── __init__.py\n│   ├── test_models.py\n│   ├── test_utils.py\n│   └── test_services.py\n├── integration/                # Integration tests\n│   ├── __init__.py\n│   ├── test_api.py\n│   └── test_database.py\n└── e2e/                        # End-to-end tests\n    ├── __init__.py\n    └── test_user_flow.py\n</code></pre>\n<h3>Test Classes</h3>\n<pre><code>class TestUserService:\n    \"\"\"Group related tests in a class.\"\"\"\n\n    @pytest.fixture(autouse=True)\n    def setup(self):\n        \"\"\"Setup runs before each test in this class.\"\"\"\n        self.service = UserService()\n\n    def test_create_user(self):\n        \"\"\"Test user creation.\"\"\"\n        user = self.service.create_user(\"Alice\")\n        assert user.name == \"Alice\"\n\n    def test_delete_user(self):\n        \"\"\"Test user deletion.\"\"\"\n        user = User(id=1, name=\"Bob\")\n        self.service.delete_user(user)\n        assert not self.service.user_exists(1)\n</code></pre>\n<h2>Best Practices</h2>\n<h3>DO</h3>\n<ul>\n<li><strong>Follow TDD</strong>: Write tests before code (red-green-refactor)</li>\n<li><strong>Test one thing</strong>: Each test should verify a single behavior</li>\n<li><strong>Use descriptive names</strong>: <code>test_user_login_with_invalid_credentials_fails</code></li>\n<li><strong>Use fixtures</strong>: Eliminate duplication with fixtures</li>\n<li><strong>Mock external dependencies</strong>: Don't depend on external services</li>\n<li><strong>Test edge cases</strong>: Empty inputs, None values, boundary conditions</li>\n<li><strong>Aim for 80%+ coverage</strong>: Focus on critical paths</li>\n<li><strong>Keep tests fast</strong>: Use marks to separate slow tests</li>\n</ul>\n<h3>DON'T</h3>\n<ul>\n<li><strong>Don't test implementation</strong>: Test behavior, not internals</li>\n<li><strong>Don't use complex conditionals in tests</strong>: Keep tests simple</li>\n<li><strong>Don't ignore test failures</strong>: All tests must pass</li>\n<li><strong>Don't test third-party code</strong>: Trust libraries to work</li>\n<li><strong>Don't share state between tests</strong>: Tests should be independent</li>\n<li><strong>Don't catch exceptions in tests</strong>: Use <code>pytest.raises</code></li>\n<li><strong>Don't use print statements</strong>: Use assertions and pytest output</li>\n<li><strong>Don't write tests that are too brittle</strong>: Avoid over-specific mocks</li>\n</ul>\n<h2>Common Patterns</h2>\n<h3>Testing API Endpoints (Flask)</h3>\n<pre><code>@pytest.fixture\ndef client():\n    app = create_app(testing=True)\n    return app.test_client()\n\ndef test_get_user(client):\n    response = client.get(\"/api/users/1\")\n    assert response.status_code == 200\n    assert response.json[\"id\"] == 1\n\ndef test_create_user(client):\n    response = client.post(\"/api/users\", json={\n        \"name\": \"Alice\",\n        \"email\": \"alice@example.com\"\n    })\n    assert response.status_code == 201\n    assert response.json[\"name\"] == \"Alice\"\n</code></pre>\n<h3>Testing Database Operations</h3>\n<pre><code>@pytest.fixture\ndef db_session():\n    \"\"\"Create a test database session.\"\"\"\n    session = Session(bind=engine)\n    session.begin_nested()\n    yield session\n    session.rollback()\n    session.close()\n\ndef test_create_user(db_session):\n    user = User(name=\"Alice\", email=\"alice@example.com\")\n    db_session.add(user)\n    db_session.commit()\n\n    retrieved = db_session.query(User).filter_by(name=\"Alice\").first()\n    assert retrieved.email == \"alice@example.com\"\n</code></pre>\n<h3>Testing Class Methods</h3>\n<pre><code>class TestCalculator:\n    @pytest.fixture\n    def calculator(self):\n        return Calculator()\n\n    def test_add(self, calculator):\n        assert calculator.add(2, 3) == 5\n\n    def test_divide_by_zero(self, calculator):\n        with pytest.raises(ZeroDivisionError):\n            calculator.divide(10, 0)\n</code></pre>\n<h2>pytest Configuration</h2>\n<h3>pytest.ini</h3>\n<pre><code>[pytest]\ntestpaths = tests\npython_files = test_*.py\npython_classes = Test*\npython_functions = test_*\naddopts =\n    --strict-markers\n    --disable-warnings\n    --cov=mypackage\n    --cov-report=term-missing\n    --cov-report=html\nmarkers =\n    slow: marks tests as slow\n    integration: marks tests as integration tests\n    unit: marks tests as unit tests\n</code></pre>\n<h3>pyproject.toml</h3>\n<pre><code>[tool.pytest.ini_options]\ntestpaths = [\"tests\"]\npython_files = [\"test_*.py\"]\npython_classes = [\"Test*\"]\npython_functions = [\"test_*\"]\naddopts = [\n    \"--strict-markers\",\n    \"--cov=mypackage\",\n    \"--cov-report=term-missing\",\n    \"--cov-report=html\",\n]\nmarkers = [\n    \"slow: marks tests as slow\",\n    \"integration: marks tests as integration tests\",\n    \"unit: marks tests as unit tests\",\n]\n</code></pre>\n<h2>Running Tests</h2>\n<pre><code># Run all tests\npytest\n\n# Run specific file\npytest tests/test_utils.py\n\n# Run specific test\npytest tests/test_utils.py::test_function\n\n# Run with verbose output\npytest -v\n\n# Run with coverage\npytest --cov=mypackage --cov-report=html\n\n# Run only fast tests\npytest -m \"not slow\"\n\n# Run until first failure\npytest -x\n\n# Run and stop on N failures\npytest --maxfail=3\n\n# Run last failed tests\npytest --lf\n\n# Run tests with pattern\npytest -k \"test_user\"\n\n# Run with debugger on failure\npytest --pdb\n</code></pre>\n<h2>Quick Reference</h2>\n<table>\n<thead>\n<tr>\n<th>Pattern</th>\n<th>Usage</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>pytest.raises()</code></td>\n<td>Test expected exceptions</td>\n</tr>\n<tr>\n<td><code>@pytest.fixture()</code></td>\n<td>Create reusable test fixtures</td>\n</tr>\n<tr>\n<td><code>@pytest.mark.parametrize()</code></td>\n<td>Run tests with multiple inputs</td>\n</tr>\n<tr>\n<td><code>@pytest.mark.slow</code></td>\n<td>Mark slow tests</td>\n</tr>\n<tr>\n<td><code>pytest -m \"not slow\"</code></td>\n<td>Skip slow tests</td>\n</tr>\n<tr>\n<td><code>@patch()</code></td>\n<td>Mock functions and classes</td>\n</tr>\n<tr>\n<td><code>tmp_path</code> fixture</td>\n<td>Automatic temp directory</td>\n</tr>\n<tr>\n<td><code>pytest --cov</code></td>\n<td>Generate coverage report</td>\n</tr>\n<tr>\n<td><code>assert</code></td>\n<td>Simple and readable assertions</td>\n</tr>\n</tbody>\n</table>\n<p><strong>Remember</strong>: Tests are code too. Keep them clean, readable, and maintainable. Good tests catch bugs; great tests prevent them.</p>\n","files":[{"path":"LICENSE","sizeBytes":1071,"isText":false},{"path":"SKILL.md","sizeBytes":19552,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"notes-only","suspicious":0,"notes":4,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-02T16:57:56.040968Z","sha256":"4B7E6EEFEFE0E5614AA260E36D6E7E1C7F5793FB88567947EDE584EB36571352","sizeBytes":6929},"review":null,"source":{"repositoryUrl":"https://github.com/beginwithu/agent-skills","path":"skills/python-testing","license":"MIT","commit":"a960304c52212f2e845067047f5cefc0c594d787","subtreeSha":"367EC337C5913FF2A18B473072F3D63AAC7B522835B60BB78F3D38BEDF1B7CF1","lastSyncedAt":"2026-12-02T16:52:59.20206Z"},"reviewedAt":"2026-12-02T17:05:55.028935Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/beginwithu/agent-skills/tree/main/skills/python-testing"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install beginwithu-agent-skills@llmmart"},{"target":"git","command":"git clone https://github.com/beginwithu/agent-skills.git"}]}