_pytest.outcomes module¶
exception classes and constants handling test outcomes as well as functions creating them
-
exception
OutcomeException
(msg: Optional[str] = None, pytrace: bool = True)[source]¶ Bases:
BaseException
OutcomeException and its subclass instances indicate and contain info about test and collection outcomes.
-
exception
Skipped
(msg: Optional[str] = None, pytrace: bool = True, allow_module_level: bool = False)[source]¶
-
exception
Failed
(msg: Optional[str] = None, pytrace: bool = True)[source]¶ Bases:
_pytest.outcomes.OutcomeException
raised from an explicit call to pytest.fail()
-
exception
Exit
(msg: str = 'unknown reason', returncode: Optional[int] = None)[source]¶ Bases:
Exception
raised for immediate program exits (no tracebacks/summaries)
-
class
_WithException
(*args, **kwds)[source]¶ Bases:
typing.Generic
-
Exception
: _ET = None¶
-
-
_with_exception
(exception_type: _ET) → Callable[[_F], _pytest.outcomes._WithException[_F, _ET]][source]¶
-
skip
(msg: str = '', *, allow_module_level: bool = False) → NoReturn[source]¶ Skip an executing test with the given message.
This function should be called only during testing (setup, call or teardown) or during collection by using the
allow_module_level
flag. This function can be called in doctests as well.- Parameters
allow_module_level (bool) – allows this function to be called at module level, skipping the rest of the module. Default to False.
Note
It is better to use the pytest.mark.skipif ref marker when possible to declare a test to be skipped under certain conditions like mismatching platforms or dependencies. Similarly, use the
# doctest: +SKIP
directive (see doctest.SKIP) to skip a doctest statically.
-
fail
(msg: str = '', pytrace: bool = True) → NoReturn[source]¶ Explicitly fail an executing test with the given message.
-
exception
XFailed
(msg: Optional[str] = None, pytrace: bool = True)[source]¶ Bases:
_pytest.outcomes.Failed
raised from an explicit call to pytest.xfail()
-
xfail
(reason: str = '') → NoReturn[source]¶ Imperatively xfail an executing test or setup functions with the given reason.
This function should be called only during testing (setup, call or teardown).
Note
It is better to use the pytest.mark.xfail ref marker when possible to declare a test to be xfailed under certain conditions like known bugs or missing features.
-
importorskip
(modname: str, minversion: Optional[str] = None, reason: Optional[str] = None) → Any[source]¶ Imports and returns the requested module
modname
, or skip the current test if the module cannot be imported.- Parameters
- Returns
The imported module. This should be assigned to its canonical name.
Example:
docutils = pytest.importorskip("docutils")