_pytest.assertion package

Module contents

support for presenting detailed information in failing assertions.

pytest_addoption(parser)[source]
register_assert_rewrite(*names)None[source]

Register one or more module names to be rewritten on import.

This function will make sure that this module or all modules inside the package will get their assert statements rewritten. Thus you should make sure to call this before the module is actually imported, usually in your __init__.py if you are a plugin using a package.

Raises

TypeError – if the given module names are not strings.

class DummyRewriteHook[source]

Bases: object

A no-op import hook for when rewriting is disabled.

mark_rewrite(*names)[source]
class AssertionState(config, mode)[source]

Bases: object

State for the assertion plugin.

install_importhook(config)[source]

Try to install the rewrite hook, raise SystemError if it fails.

pytest_collection(session: Session)None[source]
for ... in pytest_runtest_protocol(item)[source]

Setup the pytest_assertrepr_compare and pytest_assertion_pass hooks

The newinterpret and rewrite modules will use util._reprcompare if it exists to use custom reporting via the pytest_assertrepr_compare hook. This sets up this custom comparison for the test.

pytest_sessionfinish(session)[source]
pytest_assertrepr_compare(config: _pytest.config.Config, op: str, left: Any, right: Any) → Optional[List[str]][source]