I just closed the bug report quoted below with the following response: I don't agree that unit tests should run automatically. Nor do I think adding magic to the language to support unit tests is necessary when it is trivial to add some external mechanism. I guess this topic could be opened up for discussion if someone else disagrees with me. Regardless, though, it's too late for 2.1. Jeremy
">" == noreply <noreply@sourceforge.net> writes:
Bug #131480, was updated on 2001-Feb-07 18:44 Here is a current snapshot of the bug.
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