pytest_addoption添加自定义选项

 使用 自定义选项

@pytest.fixture(scope="session")
def sys_env(request):
    print(request.config.getoption("--env"))
    yield request.config.getoption("--env")

对比以下两段代码,一个很小的点。对于我区分不了 store_true 和 store 之间的不同,困扰了一会。

def pytest_addoption(parser):
    parser.addoption(
        "--env",
        action="store_true",   # 需要注意这个参数值
        default="test",
        choices=["test", "dev", "pro"],
        type=str,
        help="Keep containers after test run",
    )

 上面这一段代码,执行起来会报错。多了一个 choices 参数。

(去掉 choices 和 type 参数的话打印结果 是 true )

def pytest_addoption(parser):
    parser.addoption(
        "--env",
        action="store",  # 注意这个参数值
        default="test",
        choices=["test", "dev", "pro"],
        type=str,
        help="Keep containers after test run",
    )

上面一段代码,执行起来就是预期的结果。

有哪位大佬能告诉我在官方文档中找到 action中 store_true 和 store 的区别

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值