Overview#
Panda Pytest Assertions is a library that provides a complex assertion mechanism for use when writing tests with pytest. The primary goal is to make test code more concise, readable, and maintainable.
The library consists of two modules that can be used separately or together:
assert_context
- used to assert that the block of code behaved as expected, raise or do not raise the exception and assert the value of a result;assert_object
- used to assert the content of the object, when simple==
is not enough.
assert_context
#
This context manager asserts that a code block within a with
block behaves according to expectations. It verifies whether an exception of a specific type was (or wasn't) raised within the block and whether the result of the block (settable by the user) matches the expected value. For example:
Python | |
---|---|
assert_object
#
This function is used to assert the content of a Python object (and possibly nested objects) against provided expectations. It goes beyond simple equality checks using ==
. For instance: