Skip to content

Commit 6c0474b

Browse files
committed
docs(AGENTS): Add doctest guidelines and requirements
why: Prevent workarounds that bypass doctest execution what: - All functions/methods MUST have working doctests - Never comment out asyncio.run() or similar calls - Never convert to code-blocks (they don't run) - Stop and ask for help if doctests can't be made to work - Document available doctest_namespace fixtures - Add async doctest pattern examples
1 parent 1e176ce commit 6c0474b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

AGENTS.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,43 @@ type
213213
"""
214214
```
215215

216+
### Doctests
217+
218+
**All functions and methods MUST have working doctests.** Doctests serve as both documentation and tests.
219+
220+
**CRITICAL RULES:**
221+
- Doctests MUST actually execute - never comment out `asyncio.run()` or similar calls
222+
- Doctests MUST NOT be converted to `.. code-block::` as a workaround (code-blocks don't run)
223+
- If you cannot create a working doctest, **STOP and ask for help**
224+
225+
**Available tools for doctests:**
226+
- `doctest_namespace` fixtures: `tmp_path`, `asyncio`, `create_git_remote_repo`, `create_hg_remote_repo`, `create_svn_remote_repo`, `example_git_repo`
227+
- Ellipsis for variable output: `# doctest: +ELLIPSIS`
228+
- Skip for truly un-runnable examples: `# doctest: +SKIP` (use sparingly)
229+
- Update `pytest_plugin.py` to add new fixtures to `doctest_namespace`
230+
231+
**Async doctest pattern:**
232+
```python
233+
>>> async def example():
234+
... result = await some_async_function()
235+
... return result
236+
>>> asyncio.run(example())
237+
'expected output'
238+
```
239+
240+
**Using fixtures in doctests:**
241+
```python
242+
>>> git = Git(path=tmp_path) # tmp_path from doctest_namespace
243+
>>> git.run(['status'])
244+
'...'
245+
```
246+
247+
**When output varies, use ellipsis:**
248+
```python
249+
>>> git.clone(url=f'file://{create_git_remote_repo()}') # doctest: +ELLIPSIS
250+
'Cloning into ...'
251+
```
252+
216253
### Git Commit Standards
217254

218255
Format commit messages as:

0 commit comments

Comments
 (0)