AI Guide
Test Guide
- Use only
pytest(nounittest, no test classes). - All tests are top-level functions named
test_*. - Use
@pytest.fixturefor setup/data. - Use plain
assertfor checks. - Use
@pytest.mark.parametrizefor multiple cases. - Use
pytest.raisesfor exceptions. - Use
tmp_path/tmpdirfor temp files. - Each test must be independent.
Example:
import pytest
from mymodule import myfunc
@pytest.fixture
def sample_data():
return [1, 2, 3]
def test_myfunc_basic(sample_data):
assert myfunc(sample_data) == expected_result
@pytest.mark.parametrize("input,expected", [(1, 2), (2, 3)])
def test_myfunc_param(input, expected):
assert myfunc(input) == expected
def test_myfunc_error():
with pytest.raises(ValueError):
myfunc(bad_input)
Docstring Style Guide (PEP287 reST)
Use short, concise reST (PEP287) docstrings for all modules, classes, and functions.
Function Docstring Template
def func(arg1, arg2):
"""Short summary.
:param int arg1: Description
:param str arg2: Description
:returns bool: Description
:raises ValueError: If something goes wrong
"""
Class Docstring Template
Module Docstring Template
Best Practices
- Use a single short summary line if possible.
- Use field lists with type on the same line as param/return (e.g., :param int foo: ...)
- Only document what isn’t obvious from the signature.
- Use imperative mood for descriptions.
- Prefer single-line docstrings for trivial functions.