... | ... | @@ -23,10 +23,10 @@ Python中的文档测试与类型标注 |
|
|
|
|
|
## `doctest`模块使用
|
|
|
### `testmod()`方法
|
|
|
- 见[doctest_example.py](doctest_example.py)
|
|
|
- 见[doctest_example.py](doctest&typing/doctest_example.py)
|
|
|
|
|
|
### `testfile()`方法
|
|
|
- 见`doctest_example.py`
|
|
|
- 见[doctest_example.py](doctest&typing/doctest_example.py)
|
|
|
- 替代品 `python -m doctest -v doctest_example.txt`
|
|
|
|
|
|
## 输出内容
|
... | ... | @@ -34,14 +34,14 @@ Python中的文档测试与类型标注 |
|
|
- 若还要输出正确的,在CLI中添加`-v`参数
|
|
|
|
|
|
## 例外
|
|
|
- 见`doctest_exceptions_example.py`
|
|
|
- 见[doctest_exceptions_example.py](doctest&typing/doctest_exceptions_example.py)
|
|
|
- 常用
|
|
|
- `# doctest: +ELLIPSIS`
|
|
|
- `# doctest: +SKIP`
|
|
|
- [doctest Directives](https://docs.python.org/zh-cn/3.7/library/doctest.html#directives)
|
|
|
|
|
|
## doctest原理
|
|
|
- 见`how_doctest_works.py`
|
|
|
- 见[how_doctest_works.py](doctest&typing/how_doctest_works.py)
|
|
|
- 对象(`module`, `class`, `function`)的`__doc__`属性
|
|
|
- `globs`参数 注入测试执行上下文
|
|
|
- 可以是自己构建的`dict`可以是`locals()`, `globals()`
|
... | ... | |