compare any two python objectsbut its generality means that it cannot give particularly informative error messages from python the unittest testcase class has many more methodsincluding many data-type-specific assertion methods here is how we could write the assertion using python self assertlistequal(items[- - - ]if the lists are not equalsince the data types are knownthe unittest module is able to give more precise error informationincluding where the lists differ def test_list_fail(self)def process()nonlocal items with atomic atomic(itemsas atomicatomic append( atomic insert( - del atomic[ atomic[ - atomic poop(typo items self original_list[:self assertraises(attributeerrorprocessself assertequal(itemsself original_listto test the failure casethat iswhere an exception is raised while doing atomic processingwe must test that the list has not been changed and also that an appropriate exception has been raised to check for an exception we use the unittest testcase assertraises(methodand in the case of python we pass it the exception we expect to get and callable object that should raise the exception this forces us to encapsulate the code we want to testwhich is why we had to create the process(inner function shown here in python the unittest testcase assertraises(method can be used as context managerso we are able to write our test in much more natural waydef test_list_fail(self)items self original_list[:with self assertraises(attributeerror)with atomic atomic(itemsas atomicatomic append( atomic insert( - del atomic[ atomic[ - atomic poop(typo self assertlistequal(itemsself original_list