如果我有这两个文件:
first_module.py
def add(a, b):
"""
>>> add(1, 2) # should this not fail first?
3
"""
return a - b
second_module.py
from first_module import *
def anti_add(a, b):
"""
>>> anti_add(1, 2) # why does this fail first?
-3
"""
return -add(a, b)
我跑:
py.test --doctest-modules -x second_module.py
我得到:
========================================== FAILURES ===========================================
__________________________________ [doctest] second_module.anti_add __________________________________
005
006 >>> anti_add(1, 2) # why does this fail first?
Expected:
-3
Got:
1
.../second_module.py:6: DocTestFailure
但我认为第一次测试会先失败,因为
add
需要为
anti_add
工作。
我有时会感到困惑,因为
anti\u添加
由于中的错误,测试失败
添加
,但我在
添加
所以我假设它工作正常。
我该怎么做
py.test
以相反的方式在模块中运行测试?