To reproduce a pytest failure, I would like to run one or more tests in a specific sequence via pytest
without modifying the original source files (adding markers would not be allowed). The tests are scattered across multiple source files and I do not want to execute the other tests in those files.
For example, I’d like to run test_potato_salad and test_macaroni_salad in that order without specifying the source file name.
There may be a better solution, but this is how I did it: Unfortunately -k
doesn’t let the user simply list the test names in a comma-separated format (e.g. -k 'test_potato_salad,test_macaroni_salad'
). Markers weren’t an option here because I couldn’t change the source code, so I used some unorthodox manipulation of the keyword feature to do my bidding. Example: pytest -k 'test_potato_salad or test_macaroni_salad'
I was fortunate that pytest
executed the tests using keywords in an order that matched the sequence of the “or”; otherwise I might have been out of luck. If there is a more explicit way to execute tests by test name in a specific order I would love to learn more about it.