O'Reilly logo

Python Testing Beginner's Guide by Daniel Arbuckle

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5

Pop quiz - basic unittest knowledge

  1. class test_exceptions(TestCase):
    • def test_ValueError(self):
      • self.assertRaises(ValueError, int, '123')
  2. Use the assertAlmostEqual method.
  3. You would use assertTrue if none of the more specialized assertions suited your needs. You would use fail if you needed to express the conditions for test failure, so complex that they don't fit comfortably into a single Boolean expression.

Pop quiz - text fixtures

  1. To provide each test with an identical, isolated environment.
  2. Add setUp and/or tearDown methods to a TestCase subclass.
  3. A test fixture can consist of either or both methods, so the answer is yes.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required