assert_object
#
The assert_object
module exposes a function that asserts whether the content of a Python object (including possibly nested objects) fulfills provided expectations.
Basic Example#
Consider the following code snippet, which asserts the return value of fun()
against specific expectations.
- The object must have at least two attributes:
created_at
andbooks
. - The
created_at
attribute, when stringified, must match'2020-06-08 12:30:00'
. - The
books
attribute must be an iterable with exactly two elements. - The order of the
books
elements does not matter. - One of the
books
elements must have at leastname
,authors
, andtranslations
attributes. - Another
books
element must have at leastname
,authors
, andlanguage
attributes. - The values of the
books
elements' attributes are also checked against specified expectations.
Example of an object that fulfills the above expectation:
Python | |
---|---|