cool77 cool77 - 6 months ago 163
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

Why not test for the length of the list:

assert len(function_returns_list()) == 0, "the list is non empty"