473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1354
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Will Stuyvesant | last post by:
I have a unittest testfile like this: ----------------------- test_mod.py --------------------- import sys sys.path.append('..') import unittest import mod class...
12
by: Paul Moore | last post by:
One of the things I really dislike about Unittest (compared, say, to a number of adhoc testing tricks I've used in the past, and to Perl's "standard" testing framework) is that the...
8
by: Remy Blank | last post by:
Hello unittest users, In a project I am working on, I have a series of tests that have to be run as root, and others as a normal user. One solution is to separate the tests into two different...
0
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally...
1
by: Tom Haddon | last post by:
Hi Folks, Newbie question here. I'm trying to set up some unit testing for a database abstraction class, and the first thing I want to test is the connection parameters. So, my question is, how do...
3
by: Qiangning Hong | last post by:
I want to apply TDD (test driven development) on my project. I am working on a class like this (in plan): # file: myclass.py import _extmod class MyClass(object): def __init__(self):...
24
by: john_sips_tea | last post by:
For writing testcode, it looks like there's three ways that it's typically done: (1). using the doctest module, (2). using the unittest module (i.e. "pyunit"), or else (3). just putting an...
3
by: David Vincent | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hello I'm hoping to get some insight into a situation that seems odd to me. My Python experience is limited; I've just started using the unittest module....
0
by: Chris Fonnesbeck | last post by:
I have built the following unit test, observing the examples laid out in the python docs: class testMCMC(unittest.TestCase): def setUp(self): # Create an instance of the sampler...
3
by: Paul Moore | last post by:
My normal testing consists of a tests.py script using unittest, with the basic if __name__ == '__main__': unittest.main() incantation to get things going. But I now want to incorporate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.