Skip to content

Commit 7384da2

Browse files
authored
chore: improve test guidelines in AGENTS.md (#387)
Add explicit rules for testing public APIs only, requiring type annotations on tests/fixtures, and keeping imports at module level. Fix fixture reference to reflect the actual pytest_plugins layout. Made-with: Cursor
1 parent 351d701 commit 7384da2

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

AGENTS.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ The following ruff linter rules are currently enabled (see [pyproject.toml](pypr
507507

508508
The project uses `pytest` with the following patterns:
509509

510-
- **Fixtures**: Shared test data and configurations in [tests/conftest.py](tests/conftest.py)
510+
- **Fixtures**: Shared fixtures are provided via `pytest_plugins` from `data_designer.config.testing.fixtures` and `data_designer.engine.testing.fixtures`, plus local `conftest.py` files in each test directory
511511
- **Stub configs**: YAML-based configuration stubs for testing (see `stub_data_designer_config_str` fixture)
512512
- **Mocking**: Use `unittest.mock.patch` for external services and dependencies
513513
- **Async support**: pytest-asyncio for async tests (`asyncio_default_fixture_loop_scope = "session"`)
@@ -516,7 +516,10 @@ The project uses `pytest` with the following patterns:
516516

517517
### Test Guidelines
518518

519-
- **Parametrize over duplicate**: Use `@pytest.mark.parametrize` instead of writing multiple test functions for variations of the same behavior
519+
- **Test public APIs only**: Tests should exercise public interfaces, not `_`-prefixed functions or classes. If something is hard to test without reaching into private internals, consider refactoring the code to expose a public entry point
520+
- **Type annotations required**: Test functions and fixtures must include type annotations — `-> None` for tests, typed parameters, and typed return values for fixtures
521+
- **Imports at module level**: Follow the same import rules as production code — keep imports at the top of the file, not inside test functions
522+
- **Parametrize over duplicate**: Use `@pytest.mark.parametrize` (with `ids=` for readable names) instead of writing multiple test functions for variations of the same behavior
520523
- **Minimal fixtures**: Fixtures should be simple — one fixture, one responsibility, just setup with no behavior logic
521524
- **Shared fixtures in `conftest.py`**: Place fixtures shared across a test directory in `conftest.py`
522525
- **Mock at boundaries**: Mock external dependencies (APIs, databases, third-party services), not internal functions
@@ -530,6 +533,7 @@ from typing import Any
530533

531534
from data_designer.config.config_builder import DataDesignerConfigBuilder
532535

536+
533537
def test_something(stub_model_configs: dict[str, Any]) -> None:
534538
"""Test description."""
535539
builder = DataDesignerConfigBuilder(model_configs=stub_model_configs)

0 commit comments

Comments
 (0)