Every Python Assert Method in One List
I am constantly looking up assert methods on the Python 2 Unit Test Documentation and it's driving me crazy because that page is super long and hard to mentally parse. The lists of assert methods available are broken up in different sections on the page and I'm done searching around it.
Writing unit tests in Python obviously requires heavy use of assert methods, but for some reason they're buried in the Python documentation.
So here's a compiled list of all of them for my reference, but maybe this is useful for someone else out there too...
Python Assert Methods
|assertEqual||a == b|
|assertNotEqual||a != b|
|assertTrue||bool(x) is True|
|assertFalse||bool(x) is False|
|assertIs||a is b||2.7|
|assertIsNot||a is not b||2.7|
|assertIsNone||x is None||2.7|
|assertIsNotNone||x is not None||2.7|
|assertIn||a in b||2.7|
|assertNotIn||a not in b||2.7|
|assertNotIsInstance||not is instance(a,b)||2.7|
|assertRaises||fun(*args,**kwds) raises exc|
|assertRaisesRegexp||fun(*args,**kwds) raises exc(regex)||2.7|
|assertAlmostEqual||round(a-b,7) == 0|
|assertNotAlmostEqual||round(a-b,7) != 0|
|assertGreater||a > b||2.7|
|assertGreaterEqual||a >= b||2.7|
|assertLess||a < b||2.7|
|assertLessEqual||a <= b||2.7|
|assertItemsEqual||sorted(a) == sorted(b)||2.7|
|assertDictContainsSubset||all the key/value pairs in a exist in b||2.7|
|assertSetEqual||sets or frozensets||2.7|
Other Blog Posts
Sign Into Gmail Without Signing Into Google Chrome Recently, Google released an update to Google Chrome that effectively forces you to sign into the Google......
Four Steps To Write An AppleScript to Gather ALL Windows on OSX I have no idea why, but there is no built-in way to gather......
Four Simple Steps To Post To Twitter Using Python Automating Twitter can be an easy coding exercise once you have everything set up, but figuring......
The Mega List Of Free Image Sites For Blogging Blogging is hard work, and finding good images to make your content compelling can be even......
When You Pry It From My Cold, Dead Hands... I've been a die hard VIM user since the days of co-founding the Kalamazoo Linux Users......