Skip to content
Advertisement

Exclude some tests by default

I wish to configure pytest such that it excludes some tests by default; but it should be easy to include them again with some command line option. I only found -k, and I have the impression that that allows complex specifications, but am not sure how to go about my specific need…

The exclusion should be part of the source or a config file (it’s permanent – think about very long-running tests which should only be included as conscious choice, certainly never in a build pipeline…).

Bonus question: if that is not possible, how would I use -k to exclude specific tests? Again, I saw hints in the documentation about a way to use not as a keyword, but that doesn’t seem to work for me. I.e., -k "not longrunning" gives an error about not being able to find a file “notrunning”, but does not exclude anything…

Advertisement

Answer

You can use pytest to mark some tests and use -k arg to skip or include them.

For example consider following tests,

JavaScript

you can run pytest like this to run all the tests

JavaScript

To skip the marked tests you can run pytest like this,

JavaScript

If you want to run the marked tests alone,

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement