Test classes - how to rerun them

Dealing with imperfect code and test environments can drive you crazy, especially when you need to properly rerun failed tests while preserving the state of the test environment. How I deal with it using pytest?