XFail
XFail provides a decorator function xfail to skip expected exceptions. Similar to unittest.skipIf, but xfail can specify which exception should be skipped, and raise if the decorated function is unexpectedly passed (only if strict is True).
Install
Supported python versions are: 2.7, 3.4, 3.5, 3.6
Can be installed from PyPI by pip:
pip install xfail
Usage
xfail decorator
xfail accepts two arguments, exceptions and strict.
The first argument (exceptions) should be an Exception class to skip (Ex. Exception, AssertionError, and so on). If you want to skip multiple exceptions, use tuple of them, for example, @xfail((AssertionError, ValueError)).
The second argument strict should be a boolean. If strict is False (by default) and passed unexpectedly, raise unittest.SkipTest exception, which will mark the test is skipped. This case is very similar to the function is decorated by uniteest.skip function and the test will be counted as skipped.
If it is True and the decorated function did not raise (any of) the expected exception(s), XPassFailure exception would be raised. In this case, the test will be counted as fail.
from xfail import xfail
@xfail(IndexError)
def get(l, index):
return l[index]
l = [1, 2, 3]
get(4) # no error
Also supports multiple exceptions:
@xfail((IndexError, ValueError))
def a():
'''This function passes IndexError and ValueError
...
In test script, similar to unittest.TestCase.assertRaises:
from unittest import TestCase
from xfail import xfail
class MyTest(TestCase):
def test_1(self):
@xfail(AssertionError)
def should_raise_error():
assert False
a() # test passes
def test_2(self):
@xfail(AssertionError, strict=True)
def should_raise_error():
assert True
a() # test failes, since this function should raise AssertionError
# Can be used for test function
@xfail(AssertionError, strict=True)
def test_3(self)
assert False
# This test will fail
@xfail(AssertionError, strict=True)
def test_3(self)
assert True
For more exapmles, see test_xfail.py.
Metadata
Release files for xfail 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| xfail-1.1.2.tar.gz | 3.1 kB | Without provenance | Details |
Release files / xfail-1.1.2.tar.gz
| Download URL | xfail-1.1.2.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db965380e89e26f114292393906367939e796a4aecf998fcd6e8a775e2a10f30
|
|
BLAKE2b-256 checksum How to use checksums |
df08ca9fb927bba75e65edce89f0d5da1927a1ac42eaf18c726b7096dfb48bbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for xfail 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.