【问题标题】:Pytest CLI: how can i ignore test case by name?Pytest CLI:如何按名称忽略测试用例?
【发布时间】:2017-10-01 15:50:07
【问题描述】:

用户可以运行如下测试用例

python /test/submit.py --pytest-args "test/cases/"

这将作为

运行
pytest.main("test/cases/")`

submit.pyargparse 解析参数需要('--pytest-args', default='', type=str)

submit.py 是某个模块,其中一个 def [like initiate_test()] 将按空格分割 --pytest-args,并基于相同的分割运行 pytest -- pytest-args.

现在我想以忽略 test_name 的方式传递 --pytest-args。

但是-ignore 或-k 并没有达到我的预期。

以下是我尝试-ignore 或-k 的方法。

-ignore 似乎仅限于目录和模块。

python /test/submit.py --pytest-args "test/cases/ --ignore=test/cases/test.py::test_class::test_name"

虽然-k=test_name 执行选择性运行,但-k!=test_name 没有执行取消选择。

`python /test/submit.py --pytest-args "test/cases/ -k!=test_name"`

我也尝试了像a='-k not (test_name)'这样的shell参数

python /test/submit.py --pytest-args "test/cases/ $a" 

这不起作用,因为 $a 中有空间。

注意:我无权访问 test.py 或 submit.py,所以我不能使用标记。所以解决方案应该是关于 CLI 的。

【问题讨论】:

    标签: python command-line pytest


    【解决方案1】:

    使用python /test/submit.py --pytest-args "test/cases/ -k-test_name

    请注意,当传递给-k 参数时,要跳过的测试以- 开头。

    【讨论】:

    • 另外,我发现-k 'not test_name' 更具表现力
    • 绝对!我同意
    猜你喜欢
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    相关资源
    最近更新 更多