Skip to Main Content
Python Testing with pytest
book

Python Testing with pytest

by Brian Okken
February 2022
Intermediate to advanced content levelIntermediate to advanced
274 pages
6h 28m
English
Pragmatic Bookshelf
Content preview from Python Testing with pytest

Expecting Tests to Fail with pytest.mark.xfail

If we want to run all tests, even those that we know will fail, we can use the xfail marker.

Here’s the full signature for xfail:

 @pytest.mark.xfail(condition, ..., *, reason, run=True,
 raises=None, strict=xfail_strict)

The first set of parameters to this fixture are the same as skipif. The test is run anyway, by default, but the run parameter can be used to tell pytest to not run the test by setting run=False. The raises parameter allows you to provide an exception type or a tuple of exception types that you want to result in an xfail. Any other exception will cause the test to fail. strict tells pytest if passing tests should be marked as XPASS (strict=False) or FAIL, strict=True.

Let’s look ...

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.
Start your free trial

You might also like

Python Testing with pytest

Python Testing with pytest

Brian Okken

Publisher Resources

ISBN: 9781680509427Errata Page