Python 混合py.test和doctest
我的许多测试都是用py.test编写的,这很有意义:Python 混合py.test和doctest,python,pytest,doctest,Python,Pytest,Doctest,我的许多测试都是用py.test编写的,这很有意义: def test_some_function(): assert some_function() == 42 其他一些用户指导的函数最终会有doctest,因为它们将显示在文档中: def snub(k): """ Snub will deflarg your booblebum. >>> snub(10) 20 >>> snub('tomorrow')
def test_some_function():
assert some_function() == 42
其他一些用户指导的函数最终会有doctest,因为它们将显示在文档中:
def snub(k):
"""
Snub will deflarg your booblebum.
>>> snub(10)
20
>>> snub('tomorrow')
'carrot'
:param any k: The transspace to deflarg.
:returs any:
"""
# ...
我知道使用--doctest modules
我可以让pytest运行doctest,但是我还没有找到一种同时运行所有测试的方法
我想要的是:
all_tests.py
from my_module import snub # now this should be enough to run the doctests
def test_some_function():
assert some_function() == 42
有没有办法做到这一点?我错过什么了吗
我也很乐意使用某种生成器,在那里我可以输入要运行doctest的函数。为什么您认为需要
所有测试.py
?运行pytest--doctest模块将运行所有-doctest和pytest。我遗漏了什么吗?@PiotrDawidiuk如果测试在项目/测试
下,并且源代码在项目/src
下,并且文档提示--doctest modules
将测试所有模块doctest,那么它如何查找所有测试,不仅仅是我项目中的那些,只需在project
目录中运行pytest--doctestmodules
,它扫描所有子目录,因此包含tests
和src
。父目录不会被扫描,所以其他项目是安全的。@Piotrdawiduk,您的评论回答了这个问题。将其改写为实际答案,以便RedX能够接受,并且读者能够对其进行投票。