简体   繁体   中英

Pytest CLI: how can i ignore test case by name?

User can run test cases like below

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

this will be run as

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

submit.py argparse parse argument expects ('--pytest-args', default='', type=str)

submit.py is some module, where one of the def [like initiate_test() ] will split --pytest-args by space, and runs pytest based on same split --pytest-args .

Now I want to pass --pytest-args in such a way that it ignore test_name .

But -ignore or -k is not doing what I expect.

Below is how I tried -ignore or -k .

-ignore seems like it is limited to directory & module.

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

while -k=test_name does selective run, but -k!=test_name did not do deselection.

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

Also I tried shell parameter like a='-k not (test_name)' with

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

this does not work as there is space in $a .

Note: I don't have access to test.py or submit.py , so I cannot use markers. So solution should be with respect to CLI.

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

Note the the test to be skipped starts with a - when passing to -k argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM