This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tbicr
Recipients tbicr
Date 2014-07-07.11:25:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1404732324.49.0.351341465779.issue21930@psf.upfronthosting.co.za>
In-reply-to
Content
This proposal look preaty close to pep-463: http://legacy.python.org/dev/peps/pep-0463/, but in assertion context.

Now python test libraries have different aproach for assertions, some try use own implementations, for example, for equality `assertEqual` (`assertEqulas`), `eq_`, some use python `assert` keyword.

`assert` work fine for variables, but requred verbose wrappers for exception raising, for example:

>>> try:
...   do_raise_code()
... except Exception:
...   assert False

Test libraries already have self implementations but it still not pure python like `assert`:

unittest: `self.assertRaises`
py.test: `pytest.raises`
nose: `nose.tools.raises` or `nose.tools.assert_raises`

I propose add pure python implementation for this case because it enough popular, for example:

>>> assert do_raise_code() raises  # ok if `do_raise_code` raise any exception
>>> assert do_raise_code() raises, 'text message'  # ok if `do_raise_code` raise any exception with message
>>> assert do_raise_code() raises Exception  # ok if `do_raise_code` raise specific exception
>>> assert do_raise_code() raises Exception, 'text message'  # ok if `do_raise_code` raise specific exception with message
>>> assert do_raise_code() raises (TypeError, ValueError)  # ok if `do_raise_code` raise one of specific exceptions
>>> assert do_raise_code() raises (TypeError, ValueError), 'text message'  # ok if `do_raise_code` raise one of specific exceptions with message

Test libraries can use tham raises implementations as decorator, this proposal currently ignore similar behaviour.
Test libraries can use them raises implementations as context, this propasal currently ignore similar behaviour.
`unittest` module also has `assertRaisesRegex` method, this proposal currently ignore similar behaviour.
`unittest` module also has `assertWarns` and `assertLogs`, this proposal currently ignore similar behaviour.
Also this proposal currently ignore any access to exception object and it fields.
History
Date User Action Args
2014-07-07 11:25:24tbicrsetrecipients: + tbicr
2014-07-07 11:25:24tbicrsetmessageid: <1404732324.49.0.351341465779.issue21930@psf.upfronthosting.co.za>
2014-07-07 11:25:24tbicrlinkissue21930 messages
2014-07-07 11:25:23tbicrcreate