[issue9587] unittest.assertRaises() return the raised exception

2015-01-12 Thread Martin Panter

Changes by Martin Panter vadmium...@gmail.com:


--
nosy: +vadmium

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9587] unittest.assertRaises() return the raised exception

2010-11-02 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9587] unittest.assertRaises() return the raised exception

2010-08-16 Thread Kristján Valur Jónsson

Kristján Valur Jónsson krist...@ccpgames.com added the comment:

Pehaps it hasn't been demonstrated before, but just for the sake of argument 
(and because I'm a persistant bugger), here are the two different cases:

current:
ctxt = self.assertRaises(MyException)
with ctxt:
foo()
self.assertEqual(ctxt.exception.value, 1)

suggested:
e = self.assertRaises(MyExcetpion, foo)
self.assertEqual(e.value, 1)

The inconvenient bit about the current method is having to keep the context 
manager around.  Also note that the current way of looking at the exception 
object makes it blatantly clear that self.assertRaises() is returning an 
object.  That, imho, breaks the argument about self.assert* methods not 
returning any info.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9587] unittest.assertRaises() return the raised exception

2010-08-15 Thread Denver Coneybeare

Denver Coneybeare denver.coneybe...@gmail.com added the comment:

Michael: Do you disagree with assertRaises() returning the exception object on 
principle?  Or is this just the consensus that you got from the mailing list, 
including Guido's comment.  My particular use case is that I want to check 
certain attributes being set on the raised exception and I feel that the 
context manager approach is overkill for my tests since it's just one method 
call in the context manager.  I don't understand why it is considered odd for 
assertRaises() to return the result for further inspection... I need to get it 
some way and assertRaises() has a reference to it.  Thanks for considering this 
request further.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9587] unittest.assertRaises() return the raised exception

2010-08-15 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

Providing access to the exception on the context manager was *precisely* to 
meet the use case of wanting to make assertions about the exception. I tend to 
agree with Guido that having one of the asserts return something is a bit odd, 
but irrespective of that I don't think we should have two ways of doing exactly 
the same thing. 

In general I find that the with statement version of assertRaises looks a lot 
better than the old way of calling it, so I guess I also disagree that it is 
overkill or adds bloat.

Sorry guys.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9587] unittest.assertRaises() return the raised exception

2010-08-13 Thread Denver Coneybeare

New submission from Denver Coneybeare denver.coneybe...@gmail.com:

It would be great if unittest.assertRaises() returned the raised exception when 
it passes.  This allows the caller to easily perform further checks on the 
exception, such as its attribute values.  Currently assertRaises() returns None 
(when it doesn't return a context manager) so changing the return value should 
not break backwards compatibility.

I see that this was already discussed in issue6275 but I'd like to resurrect 
the discussion since this is a common scenario in my unit tests, and I assume 
others.  Revisions r76238 and r78110 added the ability to get the exception 
from the context manager (good) but sometimes using the context manager 
approach adds unnecessary bloat to already long-winded unit tests.

I've attached a possible patch for the py3k branch 
(unittest.assertRaises.returnex.v1.patch).  Thank you for (re)considering this 
topic :)  Also, thank you Michael Foord for your recent improvements to 
unittest... the new features are very much appreciated!

--
components: Library (Lib)
files: unittest.assertRaises.returnex.v1.patch
keywords: patch
messages: 113781
nosy: denversc, krisvale, michael.foord
priority: normal
severity: normal
status: open
title: unittest.assertRaises() return the raised exception
type: feature request
versions: Python 3.2
Added file: 
http://bugs.python.org/file18501/unittest.assertRaises.returnex.v1.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9587] unittest.assertRaises() return the raised exception

2010-08-13 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
assignee:  - michael.foord

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9587] unittest.assertRaises() return the raised exception

2010-08-13 Thread Kristján Valur Jónsson

Kristján Valur Jónsson krist...@ccpgames.com added the comment:

That was a bit abrupt, want't it?  Denver is well aware of this and said: 
but sometimes using the context manager approach adds unnecessary bloat to 
already long-winded unit tests.

I happen to agree with him and don't see why we can't discuss this some.  We 
never did discuss this fully in issue 6275, I just tempered my patch a bit to 
at least get something done.

I don't think this should be rejected out of hand simply because TBDFL said 
that its an 'odd' API for a unittest assert method.  assertRaises already 
return a context manager if called without a callable (an odd api?), and it can 
just as well return an exception if called _with_ a callable.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9587] unittest.assertRaises() return the raised exception

2010-08-13 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

Sorry, it's a reopened bug requesting a feature that has already been 
considered and rejected previously. Yes I was abrupt, my apologies - I'm trying 
to clear my backlog before I go away.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com