pytestcli:如何按名称忽略测试用例?

2024-10-01 17:39:34 发布

您现在位置:Python中文网/ 问答频道 /正文

用户可以运行下面这样的测试用例

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

这将作为

^{pr2}$

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

submit.py是某个模块,其中一个def[likeinitiate_test()]将按空间拆分--pytest args,并基于相同的拆分运行pytest--pytest args。在

现在我想通过--pytest-args,这样它就忽略了test_name。在

但是-ignore或{}没有做我期望的事情。在

下面是我如何尝试-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"`

我还尝试了shell参数,比如a='-k not (test_name)'

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

由于$a中有空间,因此这不起作用。在

注意:我无法访问测试.py提交.py,所以我不能使用标记。所以解决方案应该是关于CLI的。在


Tags: 模块用户namepytest参数pytest空间

热门问题