Skip to content

Commit 77d1545

Browse files
committed
ai(rules[AGENTS]): Add comprehensive doctest execution requirements
why: Ensure AI agents create working doctests that actually execute, not workarounds what: - Add critical rules requiring doctests to actually execute - Prohibit code-block conversions and # doctest: +SKIP as workarounds - Document available fixtures (tmp_path, doctest_namespace) - Add examples using is_allowed_version() for version-conditional tests - Add ellipsis pattern for variable output - Keep existing guidelines as additional best practices
1 parent f84b6f9 commit 77d1545

1 file changed

Lines changed: 34 additions & 5 deletions

File tree

AGENTS.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,41 @@ type
224224
"""
225225
```
226226

227-
### Doctest Guidelines
227+
### Doctests
228228

229-
1. **Use narrative descriptions** for test sections rather than inline comments
230-
2. **Move complex examples** to dedicated test files at `tests/examples/<path_to_module>/test_<example>.py`
231-
3. **Keep doctests simple and focused** on demonstrating usage
232-
4. **Add blank lines between test sections** for improved readability
229+
**All functions and methods MUST have working doctests.** Doctests serve as both documentation and tests.
230+
231+
**CRITICAL RULES:**
232+
- Doctests MUST actually execute - never comment out function calls or use placeholder output
233+
- Doctests MUST NOT be converted to `.. code-block::` as a workaround (code-blocks don't run)
234+
- If you cannot create a working doctest, **STOP and ask for help**
235+
236+
**Available tools for doctests:**
237+
- `doctest_namespace` fixtures: `tmp_path` (add more via `conftest.py`)
238+
- Ellipsis for variable output: `# doctest: +ELLIPSIS`
239+
- PEP-440 version specifiers via `is_allowed_version()` for version-conditional tests
240+
241+
**`# doctest: +SKIP` is NOT permitted** - it's just another workaround that doesn't test anything. Use the fixtures and ellipsis patterns properly.
242+
243+
**Simple doctest example:**
244+
```python
245+
>>> is_allowed_version('3.3', '<=3.5')
246+
True
247+
>>> is_allowed_version('3.3', '>3.2, <4.0')
248+
True
249+
```
250+
251+
**When output varies, use ellipsis:**
252+
```python
253+
>>> parse_document(content) # doctest: +ELLIPSIS
254+
<docutils.nodes.document ...>
255+
```
256+
257+
**Additional guidelines:**
258+
1. Use narrative descriptions for test sections rather than inline comments
259+
2. Move complex examples to dedicated test files at `tests/examples/<path_to_module>/test_<example>.py`
260+
3. Keep doctests simple and focused on demonstrating usage
261+
4. Add blank lines between test sections for improved readability
233262

234263
### Git Commit Standards
235264

0 commit comments

Comments
 (0)