[Python-bugs-list] [Bug #131480] __test__() should auto-exec at compile time

noreply@sourceforge.net noreply@sourceforge.net
Wed, 07 Feb 2001 18:44:32 -0800


Bug #131480, was updated on 2001-Feb-07 18:44
Here is a current snapshot of the bug.

Project: Python
Category: None
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: justinshaw
Assigned to : nobody
Summary: __test__() should auto-exec at compile time

Details: We can make unit testing as simple as writing the test code!
Everyone agrees that unit tests are worth while.  Python does a great job
removing tedium from the job of the programmer.  Unit test should run
automatically.  Here's a method everyone can agree to:

Have the compiler check each module for a funtion with the special name
'__test__' that takes no arguments.  If it finds it it calls it.

The problem of unit testing divides esiliy into two pieces: How to create
the code and how to execute the code.  There are many options in creating
the code but I have never seen any nice solutions to run the code
automatically
"if __name__ == '__main__':"
 doesn't count since you have to do somthing special to call the code i.e.
run it as a script.  There are of course ways to run the test code
automatically but the ways I have figured out run it on every import (way
too often especially for long tests).  I imagine there is a way to check to
see if the module is loaded from a .pyc file and execute test code
accouringly but this seems a bit kludgy.  Here are the benifits of compile
time auto-execution:

- Compatible with every testing framework.
- Called always and only when it needs to be executed.
- So simple even micro projects 'scripts' can take advantage

Disadvantages:
- Another special name, '__test__'
- If there are more please tell me!

I looked around the source-code and think I see the location where we can
do this.  It's would be a piece of cake and the advantages far outway the
disadvantages.  If I get some support I'd love to incorporate the fix.

Justin Shaw
thomas.j.shaw@aero.org

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=131480&group_id=5470