Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I skip a test (or mark it as inconclusive) in pytest while it is running?

I am aware of pytest‘s decorators to mark tests as to be skipped (conditionally). However, all those are evaluated before the test starts. I have a couple of tests that require a user interaction (those are not run on CI obivously), and if that interaction is not provided, I would like to mark these tests as, well, anything but "pass" or "fail". "Skipped" would be fine, as would be "inconclusive" or "canceled" or whatever.

Is that possible?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In pytest, it is possible to dynamically skip a test during its execution by employing the pytest.mark.skip decorator within the test itself when specific conditions are not met. If you have tests demanding user interaction and wish to label them as something other than a straightforward "pass" or "fail" when such interaction is absent, you can implement an in-test conditional assessment.

In cases where the essential interaction is unavailable, you can invoke pytest.skip("Indicate reason for skipping") within the test function. This approach allows you to signify that the test was bypassed due to the absence of prerequisites for a definite pass or fail outcome, and the result will be logged as "skipped" in the test summary.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading