我想要运行此文件中的doctests,但我不确定该如何实现:
README.md
:
# WELCOME!
This library is helpful and will help you in _many_ ways!
For example:
```
>>> import library
>>> library.helps()
True
```
< p > < em >(顺便说一下:有谁能帮我将这个突出显示为Markdown格式吗?) 我想要运行此文件中的doctests,但我不确定该如何实现:
README.md
:
# WELCOME!
This library is helpful and will help you in _many_ ways!
For example:
```
>>> import library
>>> library.helps()
True
```
< p > < em >(顺便说一下:有谁能帮我将这个突出显示为Markdown格式吗?) README
运行 doctest
:
python -m doctest -v README.md
-m
参数 告诉 Python 将以下模块作为脚本运行。当作为脚本运行时, doctest
模块会在以下文件上运行 doctest.testmod
函数。最后,-v
参数使得 doctest
以详细模式运行;如果关闭它,doctest
只有在至少一个测试失败时才会产生输出(并且如果一切成功,则不会产生任何输出)。
刚刚发现了这个phmdoctest包,它似乎可以很好地与常见的Python高亮Markdown一起使用:
Any text here for example...
```python
print(1+2)
```
sample output:
```
3
```
还有一个简单的用法:
phmdoctest README.md --outfile tests/test_readme.py
python -m pytest tests -v
在第一行中,您生成一个新的测试文件,然后仅对整个项目运行标准测试...
我是上述 phmdoctest 的作者/所有者。
编辑原始问题 README.md,并确保您想要进行测试的围栏代码块以
```python
开始运行
phmutest README.md --replmode --log
与phmdoctest相比,phmutest具有以下新功能: