标签: pytest-html

如何捕获 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 …
Run Code Online (Sandbox Code Playgroud)

console capture pytest-html

5
推荐指数
1
解决办法
9544
查看次数

如何在不更改 css 的情况下共享 pytest-html 的 html 报告

我正在使用 python 3.6 和 pytest-html 生成 HTML 报告。一切都工作顺利,但是当我向经理分享我的 html 报告时,整个文档的 css 不正确。有人可以告诉我发生这种情况的原因以及解决方案吗?

我运行时的报告视图:在此输入图像描述

当我与经理共享文档时的报告视图 在此输入图像描述

selenium python-3.x pytest-html

4
推荐指数
1
解决办法
3588
查看次数

在pytest中设置动态文件夹和报告名称

我在 Python 的 pytest 中动态设置报告名称和文件夹时遇到问题。例如:我已经在 2020-03-06 21:50 运行了所有 pytest 的测试,所以我想将我的报告存储在20200306name 的文件夹中report_2150.html。我希望它在测试完成后立即自动化并触发。

我在 VS Code 中工作,我的目标是与没有自动化经验的同事分享我的工作,所以我的目标是将其用作“单击测试开始”。

我的项目结构:

webtools/
|?? .vscode/
|???? settings.json
|?? drivers/
|?? pages/
|?? reports/
|?? tests/
|???? __init__.py
|???? config.json
|???? conftest.py
|???? test_1.py
|???? test_2.py
|?? setup.py
Run Code Online (Sandbox Code Playgroud)

代码示例:

settings.json

webtools/
|?? .vscode/
|???? settings.json
|?? drivers/
|?? pages/
|?? reports/
|?? tests/
|???? __init__.py
|???? config.json
|???? conftest.py
|???? test_1.py
|???? test_2.py
|?? setup.py
Run Code Online (Sandbox Code Playgroud)

config.json

{
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.enabled": true, …
Run Code Online (Sandbox Code Playgroud)

python pytest python-3.x pytest-html

4
推荐指数
1
解决办法
1206
查看次数

使用 pytest 禁用在控制台上打印日志输出

我正在使用 pytest 编写测试,如果验证失败,它会生成大量所需的日志。我正在使用 python 的标准日志记录模块使用 FileHandler 类将这些错误记录到文件中。我正在使用 pytest-html 生成 html 报告。一切都按预期工作,除了 pytest 将日志消息记录到终端中,这比实际测试执行花费更多时间。(想象一下在终端上记录大约 200k 条日志消息)。

pytest 中是否有任何选项可以禁用将任何日志记录到终端中,但仍然捕获并使这些日志在 html 报告中可用。如果可能的话,仍然希望记录异常或断言错误。

automated-tests pytest python-3.x pytest-html

4
推荐指数
1
解决办法
6869
查看次数

Pytest HTML 不显示图像

我正在尝试使用 pytest-html 和 selenium 生成一个独立的 html 报告。我一直在尝试将屏幕截图嵌入到报告中,但它们没有显示。\n例子

\n

我的 conftest.py 看起来像这样

\n
@pytest.fixture()\ndef chrome_driver_init(request, path_to_chrome):\n    driver = webdriver.Chrome(options=opts, executable_path=path_to_chrome)\n    request.cls.driver = driver\n    page_object_init(request, driver)\n    driver.get(URL)\n    driver.maximize_window()\n    yield driver\n    driver.quit()\n\n\n# Hook that takes a screenshot of the web browser for failed tests and adds it to the HTML report\n@pytest.hookimpl(hookwrapper=True)\ndef pytest_runtest_makereport(item):\n    pytest_html = item.config.pluginmanager.getplugin("html")\n    outcome = yield\n    report = outcome.get_result()\n    extra = getattr(report, "extra", [])\n    if report.when == "call":\n        feature_request = item.funcargs[\'request\']\n        driver = feature_request.getfixturevalue(\'chrome_driver_init\')\n        nodeid = item.nodeid\n        xfail = hasattr(report, "wasxfail")\n …
Run Code Online (Sandbox Code Playgroud)

python selenium screenshot pytest pytest-html

4
推荐指数
1
解决办法
3343
查看次数

如何在 Pycharm 中使用 pytest-html?

我已经安装了 pytest-html 并想在 pycharm 中运行 pytest 后使用它生成 html 报告。

像这样: 配置

但它弹出错误:

ERROR: file not found: html=report\result.html
Run Code Online (Sandbox Code Playgroud)

运行后。那么如何修改参数呢?

pytest pytest-html

3
推荐指数
1
解决办法
3072
查看次数

Atlassian Bamboo如何识别python pytest报告

我有一些使用pytest用Python3编写的集成测试。我正在使用pytest-html从中生成html报告。我如何使Bamboo识别/显示此报告。

python bamboo pytest pytest-html

1
推荐指数
1
解决办法
1282
查看次数

如何删除pytest-html报告中的环境表

我正在尝试删除 pytest-html 报告中存在的环境表,但我不知道该怎么做?

我附上了 pytest-html 报告 在这里输入图像描述

python pytest python-3.x pytest-html

1
推荐指数
1
解决办法
1159
查看次数