unittest -- simple question

B

Brian

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.
 
I

Ian Bicking

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.
 
J

John J. Lee

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

Yes, but people often use the convenience function unittest.main


John
 
J

Jp Calderone

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top