简体   繁体   English

有没有办法知道 pytest-html 何时创建实际的 html 文件?

[英]Is there a way to know when pytest-html create the actual html file?

I would like to know when the html and asset folder are created, after running a test via pytest.在通过 pytest 运行测试后,我想知道何时创建 html 和资产文件夹。 Is there a way to know when the file is actually created?有没有办法知道文件的实际创建时间? I have tried to use breakpoints in pycharm but I can't get the time when the file is actually created.我曾尝试在 pycharm 中使用断点,但我无法获得实际创建文件的时间。

The whole point of knowing when the file is created, is because I want to copy it in a zip file.知道文件何时创建的全部意义在于,我想将它复制到 zip 文件中。

The HTML report is written in the pytest_sessionfinish hookimpl: HTML 报告写在pytest_sessionfinish hookimpl 中:

def pytest_sessionfinish(self, session):
    report_content = self._generate_report(session)
    self._save_report(report_content)

Source . 来源

If you want to manipulate the report file in your own test run, you can do that by adding your own pytest_sessionfinish hookimpl, eg如果您想在自己的测试运行中操作报告文件,您可以通过添加自己的pytest_sessionfinish hookimpl 来实现,例如

import pathlib
import zipfile


def pytest_sessionfinish(session):
    htmlfile = session.config.getoption('htmlpath')
    if htmlfile is None:  # html report not wanted by user
        return
    htmlzip = pathlib.Path(htmlfile).with_suffix('.zip')
    with zipfile.ZipFile(htmlzip, 'w') as zip:
        zip.write(htmlfile)
        zip.write('assets/style.css')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM