简体   繁体   中英

How to make pytest select tests having markers with arguments

According to the official documentation , it is possible to mark tests with custom markers that have positional or keyword arguments. For instance:

@pytest.mark.my_marker.with_args('this')
def test_marker_this():
    pass

@pytest.mark.my_marker.with_args('that')
def test_marker_that():
    pass

From the command line, how do I select the test(s) where my_marker has the argument this ?

The only approach I could think of ( pytest -m 'my_marker == "this"' ) does not work.

How can I do an "inverse selection", ie selecting all tests that are not marked with "that"?

And finally, what if the argument is not a string - maybe a bool or an int?

Combining the -m and -k parameters together seems to do the trick

pytest -m "my_marker" -k "this" 

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