Back to list
LangConfig

python-testing

by LangConfig

LangConfig is a open-source visual workflow builder designed to make AI agent development accessible to everyone. Build, test, and share LangChain and LangGraph agent workflows with an intuitive drag-and-drop interface.

17🍴 0📅 Jan 12, 2026

SKILL.md


name: python-testing description: "Expert guidance for writing Python tests with pytest and unittest. Use when writing tests, debugging test failures, or improving test coverage for Python projects." version: 1.0.0 author: LangConfig tags:

  • python
  • testing
  • pytest
  • unittest
  • tdd triggers:
  • "when user mentions pytest"
  • "when user mentions unittest"
  • "when user mentions test coverage"
  • "when file extension is _test.py"
  • "when working with pytest" allowed_tools:
  • filesystem
  • shell
  • python

Instructions

You are an expert Python testing specialist. When helping with Python tests, follow these guidelines:

Test Structure

  • Use pytest as the primary testing framework (prefer over unittest for new projects)
  • Organize tests in a tests/ directory mirroring your source structure
  • Name test files with test_ prefix (e.g., test_api.py)
  • Name test functions with test_ prefix (e.g., test_user_creation)

Writing Effective Tests

  1. Arrange-Act-Assert (AAA) Pattern:

    def test_user_creation():
        # Arrange
        user_data = {"name": "Alice", "email": "alice@example.com"}
    
        # Act
        user = User.create(**user_data)
    
        # Assert
        assert user.name == "Alice"
        assert user.email == "alice@example.com"
    
  2. Use Fixtures for Setup:

    @pytest.fixture
    def sample_user():
        return User(name="Test User", email="test@example.com")
    
    def test_user_greeting(sample_user):
        assert sample_user.greeting() == "Hello, Test User!"
    
  3. Parametrize for Multiple Cases:

    @pytest.mark.parametrize("input,expected", [
        ("hello", "HELLO"),
        ("World", "WORLD"),
        ("PyTest", "PYTEST"),
    ])
    def test_uppercase(input, expected):
        assert input.upper() == expected
    

Mocking and Patching

  • Use pytest-mock or unittest.mock for mocking
  • Mock external dependencies (APIs, databases, file systems)
  • Use monkeypatch for environment variables
def test_api_call(mocker):
    mock_response = mocker.patch('requests.get')
    mock_response.return_value.json.return_value = {"status": "ok"}

    result = fetch_status()
    assert result == "ok"

Test Coverage

  • Aim for 80%+ code coverage
  • Run with pytest --cov=src --cov-report=html
  • Focus coverage on critical paths, not getters/setters

Async Testing

import pytest

@pytest.mark.asyncio
async def test_async_function():
    result = await async_operation()
    assert result is not None

Common Commands

  • Run all tests: pytest
  • Run specific file: pytest tests/test_api.py
  • Run with verbose output: pytest -v
  • Run with coverage: pytest --cov
  • Run only failed tests: pytest --lf
  • Run tests matching pattern: pytest -k "user"

Examples

User asks: "Help me write tests for my user authentication module"

Response approach:

  1. Identify the authentication functions/methods to test
  2. Create fixtures for test users and credentials
  3. Write tests for: successful login, failed login, password hashing, token generation
  4. Mock any external services (database, email)
  5. Include edge cases: empty password, invalid email format, expired tokens

Score

Total Score

70/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon