I'm writing unit tests for my Python app with pytest. Most of my experience with unit test writing comes from Javacript frameworks such as Jasmine, where you can mark singly mark tests to run in next test round with word 'fit' or mark test to be excluded with word 'xit'. 'fit' is nice during development when I want to run only very specific subset of tests to reduce run time and results output clutter. Xit is already implemented with mark.skip decorator, but I'd like to have fit.
How I can configure pytest to do something like following:
- Collect all tests
- Check if there is any tests marked with decorator @pytest.mark.only decorator. If any is found, run only those tests, otherwise run all tests
I'm aware that I can select tests to run with command line with -m flag, but I'd like to dynamically detect the subset of runnable tests so that during development I don't have to run tests with two different commands with one having -m flag, and other without the flag.
I suppose conftest.py could be a place to add this logic but I couldn't find much information about the configuration of it.