On 29 April 2012 00:10, Joachim Durchholz <[email protected]> wrote: > Hi all, > > I'm having a "will this cause too much surprise" question here. > I need to explain the situation, so I'm sorry for any tl;dr effects. > > as those who're watching https://github.com/sympy/sympy/pull/911 already > know, I have upgraded raises() by backporting some code from pytest. > Raises will then be able accept code in three forms: > > As a string like before: > raises(DivisionByZero, "1/0") > > As a lambda: > raises(DivisionByZero, lambda: 1/0) > The code inside the lambda does not execute before raises() is called, but > inside raises(), after all the mechanics has been set up to catch any > exceptions and report them if they aren't the expected one. > > As a with statement: > with raises(DivisionByZero): > 1/0 > This works just like the lambda but can contain statements (assignments, > loops etc.) > > Now the question is what people would do it they have two such tests to run. > For a silly example, assume testing whether 1/0 and -1/0 both throw an > exception. Would you write > > with raises(DivisionByZero): > 1/0 > with raises(DivisionByZero): > -1/0 > > or > > with raises(DivisionByZero): > 1/0 > -1/0 > > The potential issue here is that if people instinctively use the second > form, they won't get the -1/0 test: the 1/0 will raise the exception and > shortcut the entire with block. > > Now the question is whether that's a problem in practice or not. > Points to consider: > > - That an exception shortcuts the entire with block is part of the intended > purpose of with blocks, so we might say we're expecting everybody using them > to know their semantics. > - This construction with the exact same semantics is also available in > pytest. So the pytest people either consider the issue to be a nonproblem, > or they have accepted it as a necessary evil. (Is anybody able to dig up any > discussion the pytest people might have had on the issue?) > - Those who get hit by this won't notice. There won't be an error message, > just a slightly worse test coverage. > - It's a rare problem. I have applied the new lambda: and with: stuff to 99% > of all tests in SymPy, and less than a dozen or so tests actually had > statements in them. With a lambda, nobody is going to make this error. > > Should we worry, or not?
I vote for "not worry". If somebody is new and does not how to use the "with" block the reviewer will probably notice it. By the way, this is a really aesthetically pleasing way to write a test. (my main reason to vote "not worry") > Any feedback welcome. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
