Skip to main content

testing

Testing conventions using pytest. Use when writing tests, creating fixtures, or running test suites.

来源信息

仓库
meleantonio/ChernyCode
最近来源活动
2026年2月1日 11:23
检测到的 SKILL.md 语言
英语
星标
517
Forks
108

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
testing
description
Testing conventions using pytest. Use when writing tests, creating fixtures, or running test suites.
# Testing Standards ## Framework - Use pytest for all tests - Target 80%+ code coverage ## File Organization - Tests in `tests/` directory mirroring `src/` structure - Test files: `test_<module>.py` or `<module>_test.py` - Test functions: `test_<description>` ## Fixtures - Use fixtures for reusable test data - Prefer `scope="function"` unless shared state is needed - Use `conftest.py` for shared fixtures Example: ```python import pytest @pytest.fixture def sample_user(): """Create a sample user for testing.""" return User(name="Test User", email="test@example.com") def test_user_creation(sample_user): assert sample_user.name == "Test User" assert sample_user.email == "test@example.com" ``` ## Parametrization - Use `@pytest.mark.parametrize` for testing multiple inputs - Keep parameter names descriptive Example: ```python @pytest.mark.parametrize("input_val,expected", [ (1, 2), (2, 4), (0, 0), ]) def test_double(input_val, expected): assert double(input_val) == expected ``` ## Assertions - Use plain `assert` statements - Write clear assertion messages for complex checks - Test one concept per test function ## Mocking - Use `pytest-mock` or `unittest.mock` - Mock external dependencies (APIs, databases) - Avoid mocking the code under test ## Commands - Run tests: `pytest` - With coverage: `pytest --cov` - Verbose: `pytest -v` - Single file: `pytest tests/test_specific.py` - Single test: `pytest tests/test_specific.py::test_name`
在 GitHub 查看