coala: Replace assertRaises with assertRaisesRegex
Python unittest framework provides two methods for checking that an operation raises an expected exception: assertRaises
and assertRaisesRegex
.
Using unittest.assertRaises
should be avoided.
unitest.assertRaisesRegex
has an extra parameter to check the exception message, and should be used instead. By checking the exception message, the unit test verifies that the exception is precisely the one which was expected, rather than only of the same type as expected.
coala-bears has 6 unit test modules using assertRaises
, and coala has 44.
For this task, pick one unit test module, and convert it to using assertRaisesRegex
.
The easiest way to do this is
Change the method and add an unexpected message, like 'voodoo':
- with self.assertRaises(AssertionError): + with self.assertRaisesRegex(AssertionError, 'voodoo'):
Run the tests, e.g.
$ py.test-3 tests/java/CheckstyleBearTest.py .. E AssertionError: "voodoo" does not match "...."
Replace the unexpected message, like 'voodoo', with a distinctive part of the message that
py.test
reported occurred.Create a Pull Request.
Follow http://coala.io/newcomer to join the coala organisation, create your commit, and submit the pull request.
Examples:
REQUIREMENTS
- get added to the coala organization publicly.
EXPECTED OUTCOME
- Accepted pull request