New submission from Pavel Tyslyatsky:
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.
--
messages: 222450
nosy: tbicr
priority: normal
severity: normal
status: open
title: new assert raises syntax proposal
type: enhancement
versions: Python 3.5
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21930
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com