1

I'd like to configure pytest such that I have to specify a marker on the command line for tests with that marker to be run. For example, say I'm using two pytest markers: slow and perf. I'd like

$ pytest               # everything but slow and perf
$ pytest -m slow       # only slow
$ pytest -m perf       # only perf
$ pytest -m slow perf  # only slow and perf

As it is, the first case doesn't work like that - it runs everything. This means that to run everything that's not marked, I need to know what markers exist, which is awkward, but also changes over time as I add new markers.

This answer almost does it, but I don't want to edit the list of markers, because I parse that list for use in a test dashboard.

joel
  • 6,359
  • 2
  • 30
  • 55
  • Hey Joel, I believe this may help your question. [here](https://stackoverflow.com/questions/39846230/how-to-run-only-unmarked-tests-in-pytest) – Luiz Fernando Lobo Aug 09 '19 at 17:42
  • You can use `pytest --markers` to list markers. Then use some shell magic to parse the marker names and pass them to `pytest -m`, e.g. with bash: `pytest --markers | grep -Po "@pytest\.mark\.\K(.*?)(?=[\(:])" | tr '\n' ',' | xargs -I [] pytest -m "not ([])"`. – hoefling Aug 09 '19 at 22:38

0 Answers0