assertTrue() in pytest to assert empty lists

You can assert list to confirm list is not empty, or assert not list to confirm list is empty:

>>> assert not []
>>> assert []
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
>>> assert [1, 2, 3]

So in your case, you can just write down:

assert not function_returns_list()

You can read more about Truth Value Testing on python.org.


Why not test for the length of the list:

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

Tags:

Python

Pytest