Sachinlionel
Sachinlionel

Reputation: 75

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.

Upvotes: 4

Views: 2723

Answers (1)

Sanju
Sanju

Reputation: 2194

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.

One can also spell out the command line argument as -k 'not test_name'.

Upvotes: 8

Related Questions