我只是刚刚开始学习测试,所以我刚刚开始尝试使用py.test进行一些非常简单的单元测试。pytest.main(' - s')应该运行两次测试吗?
例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 ===========================
如果测试在这里跑两次?我做了搜索,但在文档中找不到任何明显的东西(尽管可能一直在寻找错误的地方)。