Using Options

We’ve used the verbose option, -v or --verbose, a couple of times already, but there are many more options worth knowing about. We’re not going to use all of the options in this book, but quite a few. You can see all of them with pytest --help.

The following are a handful of options that are quite useful when starting out with pytest. This is by no means a complete list, but these options in particular address some common early desires for controlling how pytest runs when you’re first getting started.

 $ ​​pytest​​ ​​--help
  ...​​ ​​subset​​ ​​of​​ ​​the​​ ​​list​​ ​​...
  -k EXPRESSION only run tests/classes which match the given
  substring expression.
  Example: -k 'test_method or test_other' matches
  all test functions ...

Get Python Testing with pytest now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.