python:doctest我的github-markdown文件?

问题描述 投票:8回答:2

我想从这个文件中运行doctests,我不清楚要完成它:

README.md

# WELCOME!

This library is helpful and will help you in _many_ ways!

For example:

```
>>> import library
>>> library.helps()
True
```

(旁白:任何人都可以帮我把这个突出显示为降价吗?)

python markdown doctest github-flavored-markdown
2个回答
1
投票

作为doctest的替代品,我编写了mkcodes,这是一个从markdown文件中提取代码块的脚本,因此可以在单独的文件中对它们进行测试。

这是我使用mkcodes的实际测试脚本:

mkcodes --github --output tests/docs/test_{name}.py docs
py.test tests
pyflakes tests
pep8 tests

2
投票

您可以在命令行上使用以下命令在doctest上运行README

python -m doctest -v README.md

-m parameter告诉Python将以下模块作为脚本运行。 When run as a scriptdoctest模块在以下文件中运行doctest.testmod函数。最后,-v参数使doctest以详细模式运行;如果它被关闭,doctest只有在至少一次测试失败时才产生输出(如果一切都成功,将不会产生输出)。

© www.soinside.com 2019 - 2024. All rights reserved.