Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52221

Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?"

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?"
Date 2013-08-08 15:28 -0400
References <215331fa-379f-4251-b722-44555349fbb5@googlegroups.com> <mailman.341.1375949083.1251.python-list@python.org> <292722f2-56a7-4a9d-a3ad-e65b44cac834@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.367.1375990134.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 8/8/2013 12:20 PM, adam.preble@gmail.com wrote:
> On Thursday, August 8, 2013 3:04:30 AM UTC-5, Terry Reedy wrote:

>> def test(f):
>>
>>       f.__class__.__dict__['test_'+f.__name__]

Sorry, f.__class__ is 'function', not the enclosing class. A decorator 
for a method could not get the enclosing class name until 3.3, when it 
would be part of f.__qualname__.

Use one of the other suggestions.

> Just for giggles I can mess around with those exact lines, but I did get spanked trying to do something similar.  I couldn't reference __class__ for some reason (Python 2.7 problem?).

In 2.x, old-style classes and instances thereof do not have .__class__. 
All other objects do, as far as I know.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is it possible to make a unittest decorator to rename a method from "x" to "testx?" adam.preble@gmail.com - 2013-08-07 23:32 -0700
  Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" Terry Reedy <tjreedy@udel.edu> - 2013-08-08 04:04 -0400
    Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" adam.preble@gmail.com - 2013-08-08 09:20 -0700
      Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" Terry Reedy <tjreedy@udel.edu> - 2013-08-08 15:28 -0400
  Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" Peter Otten <__peter__@web.de> - 2013-08-08 10:32 +0200
  Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" Peter Otten <__peter__@web.de> - 2013-08-08 10:50 +0200
    Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" adam.preble@gmail.com - 2013-08-08 09:17 -0700
      Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" Ned Batchelder <ned@nedbatchelder.com> - 2013-08-08 13:14 -0400
    Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" adam.preble@gmail.com - 2013-08-08 22:07 -0700
      Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" Peter Otten <__peter__@web.de> - 2013-08-09 08:31 +0200
        Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" adam.preble@gmail.com - 2013-08-11 21:25 -0700

csiph-web