Raj*_*Raj 5 console capture pytest-html
在我的 pytest 脚本中,我需要自定义pytest-HTML报告以捕获标准输出,同时写入控制台,因为我在自动化测试中有用户输入。
test_TripTick.py
import os
import sys
import pytest
from Process import RunProcess
from recordtype import recordtype
from pip._vendor.distlib.compat import raw_input
@pytest.fixture(scope="module")
def Process(request):
# print('\nProcess setup - module fixture')
fileDirectory = os.path.abspath(os.path.dirname(__file__))
configFilePath = os.path.join(fileDirectory, 'ATR220_Config.json')
process = RunProcess.RunProcess()
process.SetConfigVariables(configFilePath)
process.GetComPort(["list=PID_0180"])
def fin():
sys.exit()
request.addfinalizer(fin)
return process
def test_WipeOutReader(Process):
assert Process.WipeOutTheReader() == True
def test_LoadingKeysIntoMemoryMap(Process):
assert Process.LoadingKeysIntoMemoryMap() == True
def test_LoadingFW(Process): # only use bar
assert Process.LoadingFW() == True
def test_LoadingSBL(Process):
assert Process.LoadingSBL() == True
def test_CCIDReadForPaymentCards(Process):
assert Process.CCIDReadWrite('Payment Card') == True
Run Code Online (Sandbox Code Playgroud)
目前,如果我从 Windows 命令行运行以下命令,我会在控制台上得到输出,但HTML report.
pytest C:\Projects\TripTickAT\test_TripTick.py -s --html=Report.html --verbose
Run Code Online (Sandbox Code Playgroud)
另外,我想知道自定义HTML report可以更新file name,ordering test based on time of the execution和 的编程方式capturing the std-out。
小智 6
您可以通过以下命令使用其他标志pytest:
--capture sys并-rP通过测试。--capture sys以及-rF失败的测试通过单击“显示所有详细信息”按钮,您还可以在 html 文档中看到控制台日志,如输出所示:
请注意,这只是部分屏幕截图,但您可以向下滚动输出以查看所有控制台日志。灰色区域是控制台输出。日志打印在命令行控制台以及 html 日志控制台中。
注意:我不知道无论测试失败还是通过,命令行级别的标志都可以工作。
| 归档时间: |
|
| 查看次数: |
9544 次 |
| 最近记录: |