New submission from Johan Tufvesson <j...@hms.se>: In the unittest module, TestCase class:
If one wants to provide a more descriptive fail message compared to the default, it is often valuable to be able to refer to the arguments evaluated by the fail*- (or assert*-) method. This can be accomplished by binding names to the evaluated values before the call to the fail*-methods, and then providing a string with the values embedded as needed. This, however, can be quite cumbersome when there are a lot of calls to fail*-methods. Today: Arg1 = RealValue() Arg2 = ExpectedValue() self.failUnlessEqual(Arg1, Arg2, "Got {0}, but expected {1}.".format(Arg1, Arg2)) Proposed solution: In the fail*-methods, check if the msg argument is some kind of string (basestring?), and run the format() method on the string with the supplied arguments. This would result in code like this: self.failUnlessEqual(RealValue(), ExpectedValue(), "Got {0}, but expected {1}.") ---------- components: Library (Lib) messages: 92977 nosy: tuben severity: normal status: open title: Ability to refer to arguments in TestCase.fail* methods type: feature request versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6966> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com