This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: modernization
Type: enhancement Stage:
Components: Tests Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, pitrou, purcell, vdupras
Priority: normal Keywords: patch

Created on 2008-02-21 13:18 by vdupras, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
unittest_modern.diff vdupras, 2008-02-21 13:18
unittest_modern2.diff vdupras, 2008-08-08 11:01
Messages (9)
msg62622 - (view) Author: Virgil Dupras (vdupras) (Python triager) Date: 2008-02-21 13:18
What prompted me to do these changes is that "Backward compatibility" 
section for 2.1 and earlier. How long are we going to keep this? According 
to svn, no commit has been made on the 2.1 branch since 2003. Is it safe 
to assume no unittest change is ever going to be backported to 2.1?

Then, while I was in it, I made other changes:

 - dict.has_key(key) --> key in dict
 - raise Exception, args --> raise Exception(args)
 - try..except KeyboardInterrupt: raise except: do_stuff() --> try..except 
Exception: do_stuff()
 - __metaclass__ = type --> all classes are now object subclasses

I'm not sure about the last one. Are those 2 equivalent? Is there a reason 
to keep is as "__metaclass__ = type"?

regrtest passed for me.
msg62628 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-02-21 16:29
À propos modernizing unittest, may I suggest taking a look at #1034053. :)
msg62641 - (view) Author: Steve Purcell (purcell) (Python triager) Date: 2008-02-21 19:27
Hi Virgil; thanks for stepping up to this.  Backward compatibility was 
largely for the sake of compatibility with Jython, which was always 
lagging far behind CPython.  I doubt it's a concern these days, and the in the Python source repository should probably always be 
implemented in the nicest, cleanest way possible with the latest 

Your changes look good to me, except for the KeyboardInterrupt one -- 
unless the way Ctrl-C is handled by Python has changed in the last 
couple of years, changing this "except:" clause will stop the text-mode 
test runner from being interruptible.  Admittedly the TextTestRunner 
should somehow be given an opportunity to detect Ctrl-C in order to stop 
when asked, but this diff does not allow for that.
msg62642 - (view) Author: Virgil Dupras (vdupras) (Python triager) Date: 2008-02-21 19:43
Isn't it why KeyboardInterrupt is a subclass of BaseException instead of 
Exception (along with SystemExit)? so that "except Exception:" doesn't 
catch it?
msg62645 - (view) Author: Steve Purcell (purcell) (Python triager) Date: 2008-02-21 19:55
Yes indeed - you're exactly right; just checked now.  Then disregard my 
previous comment!
msg62651 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-02-21 20:05
All changes are looking fine to me but I haven't looked at the patch so far.

"__metaclass__ = type" is easier to write than subclassing from object.
Both are equivalent. 

>>> __metaclass__ = type
>>> class Foo: pass
>>> Foo
<class '__main__.Foo'>
>>> Foo.__bases__
(<type 'object'>,)
>>> type(Foo)
<type 'type'>
msg70900 - (view) Author: Virgil Dupras (vdupras) (Python triager) Date: 2008-08-08 11:01
This patch has gone invalid due to some recent conflicting changes. I 
remade it and I'm resubmitting it hoping that it will get applied.
msg78410 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-12-28 15:36
Will take a look.
msg78415 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-12-28 16:01
Committed in r67985, thanks!
Date User Action Args
2022-04-11 14:56:31adminsetgithub: 46406
2008-12-28 16:01:49pitrousetstatus: open -> closed
resolution: fixed
messages: + msg78415
2008-12-28 15:36:17pitrousetmessages: + msg78410
versions: + Python 2.7, - Python 2.6
2008-08-08 11:01:26vduprassetfiles: + unittest_modern2.diff
messages: + msg70900
2008-02-21 20:05:28christian.heimessetpriority: normal
keywords: + patch
2008-02-21 20:05:15christian.heimessetnosy: + christian.heimes
messages: + msg62651
2008-02-21 19:55:14purcellsetmessages: + msg62645
2008-02-21 19:43:24vduprassetmessages: + msg62642
2008-02-21 19:27:43purcellsetmessages: + msg62641
2008-02-21 17:41:33benjamin.petersonsetnosy: + purcell
2008-02-21 16:29:57pitrousetnosy: + pitrou
messages: + msg62628
2008-02-21 13:18:13vduprascreate