Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 混合py.test和doctest_Python_Pytest_Doctest - Fatal编程技术网

Python 混合py.test和doctest

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')

我的许多测试都是用py.test编写的,这很有意义:

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能够接受,并且读者能够对其进行投票。