zoukankan      html  css  js  c++  java
  • pytest文档76

    前言

    pytest 命令行中 -o 参数的作用是覆盖pytest.ini配置文件中的参数,那就意味着在ini中的参数,也可以在命令行中使用了。

    -o 参数

    pytest -h 可以查看到-o参数的使用

    -o OVERRIDE_INI, --override-ini=OVERRIDE_INI
       override ini option with "option=value" style, e.g. `-o xfail_strict=True -o cache_dir=cache`.
    

    其作用是覆盖ini配置中的"option=value",如:-o xfail_strict=True -o cache_dir=cache

    使用示例

    之前有小伙伴问到生成JUnit报告,在 pytest.ini 配置文件添加 junit_suite_name 参数可以实现

    [pytest]
    
    junit_suite_name=yoyo
    

    但是小伙伴想在命令行中实现,却没有这个参数,当时给的解决办法是在conftest.py中通过钩子函数把命令行参数注册到pytest.ini中

    # conftest.py
    def pytest_addoption(parser):
        parser.addoption(
            "--suite-name",
            action="store",
            default="yoyo",
            help="'Default yoyo"
        )
    
    
    def pytest_configure(config):
        name = config.getoption("--suite-name")
        if name:
            config._inicache['junit_suite_name']=name
    

    后来翻阅各种文档发现命令行带上-o参数就能实现,原来pytest早就设计好了

    > pytest demo --junit-xml=./report.xml -o junit_suite_name
    
  • 相关阅读:
    有些文件不需要配置,只需要放到resources下面
    RAFT算法
    HBase,region以及HFile概念
    GitHub搭建个人网站续
    sublime text 2 安装emmet插件
    前端收录
    Zepto
    将复杂form表单序列化serialize-object.js
    PHP 清除HTML代码、空格、回车换行符的函数
    Yii2 选择布局的方式
  • 原文地址:https://www.cnblogs.com/yoyoketang/p/15042462.html
Copyright © 2011-2022 走看看