473,386 Members | 1,775 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,386 software developers and data experts.

my module and unittest contend over commandline options...

using the unittest module in Python 2.3.5, I've written some test code
that ends up with

if __name__ == "__main__":
unittest.main()

Since I want to run this code in various environments, I'd initially
added some commandline options, e.g. to specify a configuration file
like so

test.py -c devtest.conf
or
test.py -c localtest.conf

etc.
However, unittest also looks for options on the commandline, and it
was complaining about unrecognized options and quitting.

I've poked around to see if I could delete the options my earlier code
consumed from the commandline buffer, before invoking unittest, but
that seems klugy. Instead, I hardwired in a testing config file name,
that always has to be local. That works pretty well, but it leaves me
wonderfing whether there would have been another clean way to allow
both my test code and unittest to have options without interfering
with one another.
Jun 27 '08 #1
2 1312
chrisber <ch***************@gmail.comwrote:
I've poked around to see if I could delete the options my earlier code
consumed from the commandline buffer, before invoking unittest, but
that seems klugy. Instead, I hardwired in a testing config file name,
that always has to be local. That works pretty well, but it leaves me
wonderfing whether there would have been another clean way to allow
both my test code and unittest to have options without interfering
with one another.
You can pass argv as a parameter to main(), so I think the best bet is
simply to build up a new argv with the options that you want to pass
through.

Another option would be to subclass unittest.TestProgram and override
parseArgs, but you'd have to copy & modify it as it doesn't seem to have
been designed to be easily extendable.
Jun 27 '08 #2
On May 2, 4:54 am, Duncan Booth <duncan.bo...@invalid.invalidwrote:
chrisber<christophberen...@gmail.comwrote:
...it leaves me
wonderfing whether there would have been another clean way to allow
both my test code and unittest to have options without interfering
with one another.

You can pass argv as a parameter to main(), so I think the best bet is
simply to build up a new argv with the options that you want to pass
through.
Aha! I scanned through my python 2.4 installataion and found this in
unittest
def __init__(self, module='__main__', defaultTest=None,
argv=None, testRunner=None,
testLoader=defaultTestLoader):
if type(module) == type(''):
self.module = __import__(module)
for part in module.split('.')[1:]:
self.module = getattr(self.module, part)
else:
self.module = module
if argv is None:
argv = sys.argv

so I see what you mean. Thanks.

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Active8 | last post by:
I did this once and can't remember how <blush> so I read the reportlab user guid. It says to unzip the reportlab archive - this is on w2k, BTW, with Python23 - to a directory and make a file...
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...
8
by: Steve Erickson | last post by:
I have a logger class that uses the Python logging module. When I call it within a program using the unittest module, I get one line in the log file for the first test, two identical ones for the...
0
by: Jeff | last post by:
Ok, so I'm working on a project right now that is being done in psp through apache. This is working fine, except that in every one of my modules I had to use the mod_python function of...
2
by: MrBlueSky | last post by:
Morning! I'm writing my first Python program, so please have patience! I'd like to redirect the output from my application's unit tests ("import unittest") to a Tkinter Text object. I found the...
10
by: Ben Finney | last post by:
Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to...
0
by: axlq | last post by:
While trying to learn the ins and outs of the php CURL library, I decided to write a php script that posts a form on the Chicago Board of Options (CBOE) web site, which returns an ASCII text file. ...
1
by: Tom Harris | last post by:
Hi, Is there a way to pass arguments to TestCases when running tests? I have a test suite that need to be configured slightly differently for 3 different products, and rather than do a hack I...
3
by: james | last post by:
Hi all, I did some quick searching but I haven't found anything like I want. It probably has to do with the terms I am searching for so if I describe what I want then I hope someone can point me...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.