Skip to content

Commit f0e705d

Browse files
committed
AGENTS(docs[doctests]): Add doctest guidelines and patterns
why: Document doctest requirements and available fixtures. what: - Add critical rules for working doctests - Document available doctest_namespace fixtures - Add async doctest pattern with asyncio.run() - Add ellipsis usage examples for variable output
1 parent d4688b9 commit f0e705d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

AGENTS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,44 @@ 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+
- Update `pytest_plugin.py` to add new fixtures to `doctest_namespace`
229+
230+
**`# doctest: +SKIP` is NOT permitted** - it's just another workaround that doesn't test anything. If a VCS binary might not be installed, pytest already handles skipping via `skip_if_binaries_missing`. Use the fixtures properly.
231+
232+
**Async doctest pattern:**
233+
```python
234+
>>> async def example():
235+
... result = await some_async_function()
236+
... return result
237+
>>> asyncio.run(example())
238+
'expected output'
239+
```
240+
241+
**Using fixtures in doctests:**
242+
```python
243+
>>> git = Git(path=tmp_path) # tmp_path from doctest_namespace
244+
>>> git.run(['status'])
245+
'...'
246+
```
247+
248+
**When output varies, use ellipsis:**
249+
```python
250+
>>> git.clone(url=f'file://{create_git_remote_repo()}') # doctest: +ELLIPSIS
251+
'Cloning into ...'
252+
```
253+
216254
### Git Commit Standards
217255

218256
Format commit messages as:

0 commit comments

Comments
 (0)