Pywikibot: Replace assertRaises with assertRaisesRegex
Python unittest framework provides two methods for checking that an operation raises an expected exception:
assertRaises
, which is not a good assertion, andunittest.assertRaises
unitest.assertRaisesRegex
which has an extra parameter to check the exception message, and should be used instead.
Pywikibot has 33 unit test modules using assertRaises
. (See Phabricator)
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 test
$ python -m unittest -v tests.http_tests .. E AssertionError: "voodoo" does not match "...."
Replace the unexpected message, i.e. 'voodoo', with a distinctive part of the message that
unittest
reported occurred.Submit your change using Gerrit
Examples:
Pywikibot: *https://gerrit.wikimedia.org/r/#/c/330099/
In a different project:
Pywikibot is a Python-based framework to write bots for MediaWiki. See https://www.mediawiki.org/wiki/Manual:Pywikibot for more information. Documentation on Gerrit can be found at https://www.mediawiki.org/wiki/Manual:Pywikibot/Gerrit. After you have successfully claimed this task on this site, please use the Phabricator task for communication.