Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'none,': 0.07; 'receipts': 0.07; 'though:': 0.07; '%s"': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; 'unittest': 0.09; 'def': 0.12; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'skip:@ 20': 0.16; 'subject:possible': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'pass': 0.26; 'header:X -Complaints-To:1': 0.27; 'cool': 0.30; 'assert': 0.31; 'class': 0.32; 'subject:from': 0.34; 'skip:s 30': 0.35; 'subject:?': 0.36; 'wrong': 0.37; 'question,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'subject:get': 0.81; 'otten': 0.84; 'approach.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Is it possible to get string from function? Date: Thu, 16 Jan 2014 15:50:06 +0100 Organization: None References: <1389869982.38511.YahooMailBasic@web163803.mail.gq1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b66c.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389883815 news.xs4all.nl 2854 [2001:888:2000:d::a6]:51191 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64084 Albert-Jan Roskam wrote: > On Thu, 1/16/14, Peter Otten <__peter__@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.