- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想从这个文件运行 doctests,但我不清楚如何完成它:
README.md
:
# WELCOME!
This library is helpful and will help you in _many_ ways!
For example:
```
>>> import library
>>> library.helps()
True
```
(旁白:谁能帮我把这个高亮显示为 markdown?)
最佳答案
您可以在命令行上的README
上运行doctest
:
python -m doctest -v README.md
-m
parameter告诉 Python 将以下模块作为脚本运行。 When run as a script , doctest
模块运行 doctest.testmod
对以下文件的功能。最后,-v
参数使 doctest
以详细模式运行;如果它被关闭,doctest
只在至少一个测试失败时产生输出(如果一切都成功则不会产生输出)。
关于python:doctest我的github-markdown文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23250068/
我正在使用 doctest ,并且喜欢我可以从定义它们的地方测试非导出函数的事实: module Foo (frobnicate) where -- | -- >>> randomInt = 42 -
我有一个简单的 function with a doctest ,当使用 Sphinx 的 make doctest 运行时,出现以下错误: File "scheemey.rst", line ?,
文档似乎不太清楚如何解决以下问题...... def test(): """ >>> import doctest >>> doctest.ELLIPSIS_MARKER =
我通常使用 code auto-formatter Black ,它训练我使用双引号。使用双引号已成为我的“肌肉内存”。 许多类的默认 repr 使用单引号从 Python 交互式输出中打印出来。我知
我需要对一个必须用装饰器包装的方法进行文档测试,该装饰器不将 @functools.wraps 或 functools.update_wrapper 应用于被包装的方法.在这种情况下,doctest
我很困惑为什么 doctest.testmod() 以奇怪的顺序调用测试函数 from doctest import testmod def test_forwrite(): '''
import doctest def create_grid(size): grid = [] for i in range(size): row = ['0']*size
这可能是一个愚蠢的问题。 我正在尝试使用 python doctest,并且尝试运行 this示例 结尾为 if __name__ == "__main__": import doctest
我正在创建一个程序宏,它从一些配置文件自动生成一个库(这是一个寄存器布局,但这对问题并不重要)。 我希望库自动生成伴随自动库的文档,并包含应与 cargo test 一起运行的文档测试。现在,我已经实
这个问题在这里已经有了答案: How do you handle the "could not parse code block as Rust code" rustdoc warning? (1
我正在为一个模块编写文档,该模块具有一些由 Cargo 功能标志控制的选项。我想始终显示此文档,以便 crate 的消费者知道它可用,但我只需要在启用该功能时运行该示例。 库.rs //! This
我的函数从文件中读取,需要以独立于绝对路径的方式编写 doctest。编写 doctest 的最佳方法是什么?编写临时文件的成本很高,而且不是万无一失的。 最佳答案 您可以有一个采用路径的参数,用下划
如果我需要在 doctest 中做一些事情怎么办: ''' >>> for i in range(5): print i ''' 我明白了 for i in range(5):
我正在尝试通过 iex 使用 doctest 测试 HashSet。如果我运行下面的行,它会给出相同的结果,但是 #HashSet}无法在语法中表示。我想不出一种正确表示它的方法,也找不到任何例子。谢
我已经进行了搜索,但找不到我想要的东西。 我的代码如下: import datetime import doctest import os def parseOptions(): import
我有一个函数可以使用 random 模块将用户输入变量与随机生成的数字进行比较。我想写一个 doctest,它将要求忽略或覆盖随机生成的数字。 在我无知的情况下,我试图给随机变量赋值,但仍然生成了一个
测试这样的代码的最佳方法是什么(下面的代码显然失败了,因为每次都在不同的 block 中创建对象): def get_session(db_name, verbose, test): """Retur
我已经编写了一个用于测试的assert_raised 上下文管理器,它检查是否按预期引发异常,如果没有引发AssertionError。我还写了一个 doctest 来测试这个,但是 doctest
我有一个 doctest,我在其中测试 float 转换: >>> float('fish') 在 Python >> float('fish') ValueError:... 你可以看到 Alex
假设我有以下代码: def foo(s): """A dummy function foo. For example: >>> a = '''This is a test string lin
我是一名优秀的程序员,十分优秀!