473,756 Members | 3,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1336
chrisber <ch************ ***@gmail.comwr ote:
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.TestPr ogram 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...@i nvalid.invalidw rote:
chrisber<christ ophberen...@gma il.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=Non e,
argv=None, testRunner=None ,
testLoader=defa ultTestLoader):
if type(module) == type(''):
self.module = __import__(modu le)
for part in module.split('. ')[1:]:
self.module = getattr(self.mo dule, 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
5388
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 called reportlab.pth in the pythod dir. The only line in this file is supposed to be the path to the reportlib dir. Then I'm instructed to open the ... ok I'll close and reopen ... the python cmd line interpreter and type import reportlab
0
2054
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 TestCase.skipIf(expr, msg): skips if expr is true These can be called either in setUp() or in the test methods. I also added reporting of skipped tests to TestResult, _TextTestResult and
8
1999
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 second, etc. I'm using local variables, which should go out of context with each test. Setting the 'propagate' property to False doesn't have any affect. import logging, os, signal, sys from datetime import datetime
0
1357
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 apache.import_module for its autoreload capability. Now I cannot open or run any of my classes in the interpreter without getting a "No module named _apache" error. I need to get this working, as I am without unittesting right now. I also tried making...
2
3112
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 magic to redirect stdout and stderr: sys.stdout = myTextWindow sys.stderr = myTextWindow where myTextWindow inherits from Text and implements write() and writelines().
10
3771
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 be run as commands to a file with no extension. This allows other programs to use the command as an interface, and I can re-write the program in some other language
0
2767
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. CBOE appears to keep your form query data in cookies, so this seemed like a good use of curl. Well, my script works just fine when run from the commandline. When accessed from my browser, it returns an empty string where the data should be....
1
2315
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 wondered if there was a canonical way to do it. I _know_ that py.test can do it trivially. I am rather stuck with unittest, as I have 84 testcases, and I have to make it work tomorrow.
3
1434
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 to a good module. I want to take input from the user at the command line. e.g.) Would you like to continue : y What is your favorite color: green
0
9455
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.