Feb-13-2020, 09:18 PM
Have a look at this very simple utaw library. It wraps the unittest assert... functions so that they can be used from ordinary code.
If you don't like AssertionError's, you can even tweak it so that assertions raise your custom exception:
If you don't like AssertionError's, you can even tweak it so that assertions raise your custom exception:
import utaw class MyError(Exception): pass utaw.assertIn.__self__.failureException = MyError def main(): """Test two lists match.""" by_hand = [1, 2, 3, 4] by_range = list(range(1, 6)) utaw.assertListEqual(by_hand, by_range) if __name__ == '__main__': main()Note that the failureException is documented in unittest, but changing it as above is not "playing fair" with the framework. We should perhaps subclass failureException.