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

  • 相关阅读:
    git 操作
    vim使用指北 ---- Multiple Windows in Vim
    Unity 异步网络方案 IOCP Socket + ThreadSafe Queue
    unity 四元数, 两行等价的代码
    golang的项目结构 相关知识
    stencil in unity3d
    一段tcl代码
    16_游戏编程模式ServiceLocator 服务定位
    15_游戏编程模式EventQueue
    14_ Component 游戏开发组件模式
  • 原文地址:https://www.cnblogs.com/Tester_Dolores/p/13225273.html
Copyright © 2011-2022 走看看