简体   繁体   English

Pytest 与warcio集成

[英]Pytest integration with warcio

The core issue is that when running a pytest, warcio.capture_http fails to capture any of the responses and requests.核心问题是在运行 pytest 时, warcio.capture_http无法捕获任何响应和请求。

from warcio.capture_http import capture_http
import requests


def test_archive():
    url = 'http://httpbin.org/get'
    fn = 'is-it-captured.warc.gz'

    with capture_http(fn):
        requests.get(url=url)


if __name__ == '__main__':
    test_archive()

If the code snippet above is executed as python test_random.py , then the WARC output is as expected;如果上面的代码片段执行为python test_random.py ,那么 WARC output 符合预期; the filesize is larger than 0 bytes.文件大小大于 0 字节。 However, if the code is executed as pytest test_random.py then it fails to capture any of the data, and the resulting WARC file is 0 bytes.但是,如果代码作为pytest test_random.py执行,则它无法捕获任何数据,并且生成的 WARC 文件为 0 字节。

I have been stuck on this problem for the last two days and cannot figure out why this is happening.在过去的两天里,我一直被困在这个问题上,无法弄清楚为什么会这样。 Any help would be appreciated.任何帮助,将不胜感激。

This issue has now been resolved.现在这个问题已经解决了。 The error was that dash plugin for pytest was loading prior to the patching.错误是pytestdash插件在修补之前加载。 Had to disable the plugin to get the expected behaviour.必须禁用插件才能获得预期的行为。

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

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