cool77 cool77 - 1 year ago 564
Python Question

assertTrue() in pytest to assert empty lists

is there a way to use assertTrue() or assertFalse() like a function in pytest for python unittests.
I have a function which if returns with list of elements, the test needs to get failed through assertion.

is there anything like below:

assertFalse(function_returns_list()), "the list is non empty, contains error elements"

Answer Source

Why not test for the length of the list:

assert len(function_returns_list()) == 0, "the list is non empty"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download