Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Utaw library
#1
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:

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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020