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_atandbooks. - The
created_atattribute, when stringified, must match'2020-06-08 12:30:00'. - The
booksattribute must be an iterable with exactly two elements. - The order of the
bookselements does not matter. - One of the
bookselements must have at leastname,authors, andtranslationsattributes. - Another
bookselement must have at leastname,authors, andlanguageattributes. - The values of the
bookselements' attributes are also checked against specified expectations.
Example of an object that fulfills the above expectation:
| Python | |
|---|---|