我才刚刚开始学习测试,所以我刚开始尝试使用 py.test 组合并运行一些非常简单的单元测试。
示例test_script.py
:
import pytest
def test_func():
assert True
pytest.main('-v')
运行这个给出:
============================= test session starts ==============================
platform win32 -- Python 3.3.1 -- pytest-2.3.4 -- C:\Program Files (x86)\Python33\python.exe
collecting ... collected 1 items
test_script.py:3: test_func PASSED
=========================== 1 passed in 0.12 seconds ===========================
如果我替换-v
为-s
查看标准输出(并禁用标准输出的 pytest 捕获),则测试运行两次:
============================= test session starts ==============================
platform win32 -- Python 3.3.1 -- pytest-2.3.4
============================= test session starts ==============================
platform win32 -- Python 3.3.1 -- pytest-2.3.4
collected 1 items
test_script.py .
=========================== 1 passed in 0.04 seconds ===========================
collected 1 items
test_script.py .
=========================== 1 passed in 0.12 seconds ===========================
测试应该在这里运行两次吗?我进行了搜索,但在文档中找不到任何明显的内容(尽管可能一直在寻找错误的地方)。