472,119 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

unittest -- simple question

Hello;

I am writing my test modules that are separate from the modules they
test. The test modules can be invoked with if __name__ == "__main__" when
run from a command line. Right now, if __name__ == "__main__", the test
module executes runTests(), which defines a suite of tests. From the
module being tested, I am calling into the test module -- to the function
runTests(), if __name__ == "__main__".

Is this how people make the tests executable from the module be tested?

Many thanks,

Brian.
Jul 18 '05 #1
3 1289
On Nov 1, 2003, at 10:30 PM, Brian wrote:
I am writing my test modules that are separate from the modules they
test. The test modules can be invoked with if __name__ == "__main__"
when
run from a command line. Right now, if __name__ == "__main__", the test
module executes runTests(), which defines a suite of tests. From the
module being tested, I am calling into the test module -- to the
function
runTests(), if __name__ == "__main__".

Is this how people make the tests executable from the module be tested?


If I understand what you're saying, you have something like:

def runTests():
....

if __name__ == '__main__':
runTests()

? If so, then yes, this is the conventional and approved way to make
any module into a simple program, tests included.

--
Ian Bicking | ia**@colorstudy.com | http://blog.ianbicking.org
Jul 18 '05 #2
Brian <ba***@sympatico.ca> writes:
[...]
Is this how people make the tests executable from the module be tested?


Yes, but people often use the convenience function unittest.main
John
Jul 18 '05 #3
On Sat, Nov 01, 2003 at 11:30:20PM -0500, Brian wrote:
Hello;

I am writing my test modules that are separate from the modules they
test. The test modules can be invoked with if __name__ == "__main__" when
run from a command line. Right now, if __name__ == "__main__", the test
module executes runTests(), which defines a suite of tests. From the
module being tested, I am calling into the test module -- to the function
runTests(), if __name__ == "__main__".

Is this how people make the tests executable from the module be tested?


I typically decorate my modules with the following preable:
# -*- test-case-name: package.test.test_modulename -*-

and then hit F9 when I want the tests to run.

Jp

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Will Stuyvesant | last post: by
12 posts views Thread by Paul Moore | last post: by
8 posts views Thread by Remy Blank | last post: by
reply views Thread by Remy Blank | last post: by
1 post views Thread by Tom Haddon | last post: by
3 posts views Thread by Qiangning Hong | last post: by
24 posts views Thread by john_sips_tea | last post: by
3 posts views Thread by David Vincent | last post: by
reply views Thread by Chris Fonnesbeck | last post: by
3 posts views Thread by Paul Moore | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.