pytest.skip
The @pytest.mark.skipif decorator is very handy, but the mark must evaluate the condition at import/collection time, to determine whether the test should be skipped. We want to minimize test collection time, because, after all, we might end up not even executing all tests if the -k or --lf flags are being used, for example.
Sometimes, it might even be almost impossible (without some gruesome hack) to check whether a test should be skipped during import time. For example, you can make the decision to skip a test based on the capabilities of the graphics driver only after initializing the underlying graphics library, and initializing the graphics subsystem is definitely not something you want to do at import time.
For those cases, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access