Re: [Pyunit-interest] Feature Request: Make TestCase a new-style class
Brought to you by:
purcell
From: <je...@zo...> - 2002-08-08 16:04:14
|
>>>>> "SP" == Steve Purcell <ste...@ya...> writes: SP> Jim Fulton wrote: >> Steve Purcell wrote: >> >Excellent suggestion. I shall make it so. >> >> Great. Will you update the Python distribution in time for 2.3? SP> Today I checked the requested change into both the PyUnit and SP> Python CVS trees. I'm not aware of any possible breakage that SP> could result from the change, so concerned PyUnit users should SP> feel free to comment on the mailing list if they see any SP> potential problems. I've been meaning to mention that str(klass) works differently with a new-style class than with a classic class. As a result, the output from a verbose test run produces different results. Python 2.3a0 (#2, Aug 6 2002, 06:20:27) [GCC 2.95.3 19991030 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... pass ... >>> str(Foo) "<class '__main__.Foo'>" >>> "%s.%s" % (Foo.__module__, Foo.__name__) '__main__.Foo' Here's a classic class: >>> class Bar: ... pass ... >>> str(Bar) '__main__.Bar' >>> "%s.%s" % (Bar.__module__, Bar.__name__) '__main__.Bar' I think the solution is to write a helper function. def strclass(cls): return "%s.%s" % (cls.__module__, cls.__name__) And use it everywhere that a class is passed to a format string, e.g. '"%s" % cls'. Jeremy |