- pytest Quick Start Guide
- Bruno Oliveira
- 126字
- 2021-07-16 17:51:30
Keyword expressions: -k
Often, you don't exactly remember the full path or name of a test that you want to execute. At other times, many tests in your suite follow a similar pattern and you want to execute all of them because you just refactored a sensitive area of the code.
By using the -k <EXPRESSION> flag (from keyword expression), you can run tests whose item id loosely matches the given expression:
λ pytest -k "test_parse"
This will execute all tests that contain the string parse in their item IDs. You can also write simple Python expressions using Boolean operators:
λ pytest -k "parse and not num"
This will execute all tests that contain parse but not num in their item IDs.