Is it possible to get string from function?

Peter Otten __peter__ at web.de
Thu Jan 16 09:50:06 EST 2014


Albert-Jan Roskam wrote:

> On Thu, 1/16/14, Peter Otten <__peter__ at web.de> wrote:

>>  class Foo(unittest.TestCase):
>>      @unique_receipt("foo")
>>      def test_t1(self, RECEIPT):
>>          pass

>  Very cool approach. Question, though: what would be wrong
>  with the following approach:
> 
> 
> import unittest
> 
> class Test(unittest.TestCase):
> 
>     receipts = {}
> 
>     def unique_value(self, k, v):
>         assert Test.receipts.get(k) is None, "Duplicate: %s" % v
>         Test.receipts[k] = v
> 
>     def test_a(self):
>         self.unique_value("large_value", "foo")

Nothing.




More information about the Python-list mailing list