Search code examples
python-3.xassert

How do you assert an empty list in Python?


def test_negative_case(get_maximum):
    a=[]
    assert get_maximum (1,3,k,)== None, "Test case failed"
    assert get_maximum(a)== None, "Test case failed"

It doesn't respond to the test case when I input an empty list, is there a way to do so?


Solution

  • How to assert an empty list?

    assert get_maximum(a) == []
    

    or, if it always returns a list and you already tested it:

    assert not get_maximum(a)
    

    And there's no need to add that "Test case failed" afterwards.