[Jonathan, please don't send me copies of messages sent to the discussion thread. I follow comp.lang.python via a non-mail interface, and it's irritating to get unwanted copies of messages via email.]
Jonathan Fine <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > > Jonathan Fine <[EMAIL PROTECTED]> writes: > >> plus(2, '', _ex=TypeError) > > > > This second example seems counterintuitive. Is '_ex' part of the > > public interface? If so, why does it follow the convention for > > "not part of the public interface" (i.e. it is named with an > > underscore)? > > [...] > The line > plus(2, '', _ex=TypeError) > causes something to be recorded, and when the test is run the _ex > argument is filtered off, and the remaining arguments passed to the > plus function, as imported from mymod. That's confusing, then, for two reasons: It looks like '_ex' is an argument to the 'plus' function, which otherwise (probably by design) looks exactly like a call to the 'plus' function the programmer is testing. Since this is, instead, an assertion *about* that function, it is misleading to see it as an argument *to* the function. It uses the "leading-underscore" convention which means "this is not part of the public interface, and you'd better know what you're doing if you use this externally". > Finally, if you can think of a better way of saying, in Python, "The > function call plus(2, '') raises a TypeError", please let me know, > and I'll consider using it in the next version of Metatest. I would think an explicit function call that says what it's doing would be better. The unittest module implements this as: self.failUnlessRaises(TypeError, plus, 2, '') or more generally: func = plus func_args = [2, ''] self.failUnlessRaises(TypeError, func, *func_args) which has the benefit of being explicit about what it's doing. -- \ "Sometimes I -- no, I don't." -- Steven Wright | `\ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list