zoukankan      html  css  js  c++  java
  • Python 分布式执行测试用例

    pytest-parallel 库

    安装

    pipenv install pytest-parallel

    使用

    --workers auto 多进程

    缺陷

    暂时不知道如何使fixture只执行一次

    pytest-xdist 库

    安装

    pipenv install pytest-xdist

    使用

    -n auto
    --dist=loadscope 按class分配进程
    --dist=loadfile 按文件名分配进程

    问题

    一、如何使session级别fixture只执行一次,其他用例在测试时调用文件
    添加 FileLock 库,安装: pipenv install filelock
    @pytest.fixture(scope="session")
    def testfixture1():
    with FileLock("session.lock"):
    login(account,password)

    二、pytest-html 的pytest_runtest_makereport 和 xdist存在冲突,使用report.description会报assert crashitm错误!
    解决方案:
    1.删除report.description,替换成显示在extra里
    2.此时执行代码,还是会有部分用例在用例执行失败时报错 assert crashitm,查看html官网,添加 (tryfirst=True, hookwrapper=True)

    @pytest.mark.hookwrapper(tryfirst=True, hookwrapper=True)
    def pytest_runtest_makereport(item):
    pytest_html = item.config.pluginmanager.getplugin("html")
    outcome = yield
    report = outcome.get_result()
    description = description_html(item.function.__doc__)
    extra = getattr(report, "extra", [])
    desc_html = "<p>Description:%s;</p>" % (description)
    extra.append(pytest_html.extras.html(desc_html))
    if report.when == "call" or report.when == "setup":
    xfail = hasattr(report, "wasxfail")
    if (report.skipped and xfail) or (report.failed and not xfail):
    html = (
    "<div><p>Request URL:%s;</p>"
    "<p>Response:%s</p>"
    "<p>Request header:%s</p></div>"
    % (resp.request.url, resp.json(), resp.request.headers)
    )
    extra.append(pytest_html.extras.html(html))
    report.extra = extra

  • 相关阅读:
    Android自己定义组件系列【1】——自己定义View及ViewGroup
    LeetCode60:Permutation Sequence
    GitHub 优秀的 Android 开源项目
    view变化监听器ViewTreeObserver介绍
    android中ImageView的ScaleType属性
    Android静态图片人脸识别的完整demo(附完整源码)
    理解Android的手势识别
    Android浏览图片,点击放大至全屏效果
    Android中如何实现文件下载
    Android语音识别
  • 原文地址:https://www.cnblogs.com/Tester_Dolores/p/13225273.html
Copyright © 2011-2022 走看看