[Fixed]-Test if ValidationError was raised

28👍

assertRaises is used as a context manager:

def test_validate_percent(self):
    with self.assertRaises(ValidationError):
        validate_percent(1000)

or with a callable:

def test_validate_percent(self):
    self.assertRaises(ValidationError, validate_percent, 1000)

3👍

def test_validate_percent(self):
    self.assertRaises(ValidationError, validate_percent, 1000)

Leave a comment