<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
The problem is that parse_args() is implicitly accessing shared
global state, sys.argv. You need to refactor your code so that you
can control what argument list it accesses, as Dan described. You'll
need to refactor you code down to that call, and pass the arguments
to it explicitly.<br>
<br>
--Ned.<br>
<br>
<div class="moz-cite-prefix">On 10/31/2012 2:56 AM, Tim Aerdts
wrote:<br>
</div>
<blockquote
cite="mid:CAL7w2Fj+yeHPq5b0+0X=OG2NJOWD=FhS03W1yQzwTU3jUiWT1w@mail.gmail.com"
type="cite">Hello Dan,
<div><br>
</div>
<div>Thanks for your reply! However I can not use a custom
argslist. I am testing some methods and functions that call a
function get_opts() which parses the options. So I do not do any
parse_args() calls in my tests or anywhere near it.</div>
<div><br>
</div>
<div>I've more or less solved it by adding </div>
<div><br>
</div>
<div>
<div> parser.add_option('--with-coverage')</div>
<div> parser.add_option('--with-xunit')</div>
<div> parser.add_option('--cover-xml')</div>
<div> parser.add_option('--verbose')</div>
<div> parser.add_option('--cover-package')</div>
<div> parser.add_option('--nocapture')</div>
</div>
<div><br>
</div>
<div>To the parser, but I am sure this is not the way to go.</div>
<div><br>
</div>
<div>Also my setup of optparse might not be that ideal. Everytime
I need to get something from the arguments I make a call to
get_opts() which returns the options from parse_args() so if I
need something called myval I always do get_opts().myval</div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>-Tim</div>
<div><br>
<div class="gmail_quote">On Tue, Oct 30, 2012 at 8:45 PM, Dan
Wandschneider <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:daniel.wandschneider@schrodinger.com"
target="_blank">daniel.wandschneider@schrodinger.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Tim-</div>
<div>optparse.parse_args() parses all arguments given on the
command line, so it is probably balking on the commands
that you gave to Nose. In tests, you should create the
specific argument list that you want to test, and then
run parser.parse_args(arglist). For example:</div>
<div> argslist = ['-h']</div>
<div> with assertRaises(SystemExit):</div>
<div> myparser.parse_args(argslist)</div>
<div><br>
</div>
<div>If your parser is wrapped in a function or method, use
this:</div>
<div>
def my_parsing_function(args=None):</div>
<div> myparser.parse_args(args)</div>
<div><br>
</div>
<div>If args == None, OptParse will use sys.argv, so your
production code is safe. (Also, if you are writing new
code, I believe that ArgParse is preferred to OptParse)</div>
<div><br>
</div>
-Dan W.
<div><a moz-do-not-send="true"
href="http://www.schrodinger.com/" target="_blank">http://www.schrodinger.com/</a><br>
<br>
<div class="gmail_quote">On Tue, Oct 30, 2012 at 12:00 PM,
<span dir="ltr"><<a moz-do-not-send="true"
href="mailto:testing-in-python-request@lists.idyll.org"
target="_blank">testing-in-python-request@lists.idyll.org</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Send
testing-in-python mailing list submissions to<br>
<a moz-do-not-send="true"
href="mailto:testing-in-python@lists.idyll.org"
target="_blank">testing-in-python@lists.idyll.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web,
visit<br>
<a moz-do-not-send="true"
href="http://lists.idyll.org/listinfo/testing-in-python"
target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
or, via email, send a message with subject or body
'help' to<br>
<a moz-do-not-send="true"
href="mailto:testing-in-python-request@lists.idyll.org"
target="_blank">testing-in-python-request@lists.idyll.org</a><br>
<br>
You can reach the person managing the list at<br>
<a moz-do-not-send="true"
href="mailto:testing-in-python-owner@lists.idyll.org"
target="_blank">testing-in-python-owner@lists.idyll.org</a><br>
<br>
When replying, please edit your Subject line so it is
more specific<br>
than "Re: Contents of testing-in-python digest..."<br>
<br>
Today's Topics:<br>
<br>
1. Testing optparse with Nosetests (Tim Aerdts)<br>
2. Re: Testing optparse with Nosetests (Tim Aerdts)<br>
<br>
<br>
---------- Forwarded message ----------<br>
From: Tim Aerdts <<a moz-do-not-send="true"
href="mailto:fragger123@gmail.com" target="_blank">fragger123@gmail.com</a>><br>
To: <a moz-do-not-send="true"
href="mailto:testing-in-python@lists.idyll.org"
target="_blank">testing-in-python@lists.idyll.org</a><br>
Cc: <br>
Date: Tue, 30 Oct 2012 09:42:49 +0100<br>
Subject: [TIP] Testing optparse with Nosetests<br>
Hello,
<div><br>
</div>
<div>Posting this here because it seems more active
then the Nosetests users list.</div>
<div>Anyway I am in the process of writing an
application which makes use of Optparse. I'm running
the tests with Nosetests but I fear these two might
be interfering?</div>
<div><br>
</div>
<div>When I run parser.parse_args() anywhere in my
code Nosetests bugs out.</div>
<div><br>
</div>
<div>
<div>Usage: nosetests [options]</div>
<div>nosetests: error: no such option:
--with-coverage</div>
<div><br>
</div>
<div>Removing the call to parse_args() and
everything runs fine.</div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
-- <br>
Kind regards,<br>
Tim Aerdts<br>
<a moz-do-not-send="true" href="http://www.tuimz.nl"
target="_blank">http://www.tuimz.nl</a><br>
</div>
<br>
<br>
---------- Forwarded message ----------<br>
From: Tim Aerdts <<a moz-do-not-send="true"
href="mailto:fragger123@gmail.com" target="_blank">fragger123@gmail.com</a>><br>
To: <a moz-do-not-send="true"
href="mailto:testing-in-python@lists.idyll.org"
target="_blank">testing-in-python@lists.idyll.org</a><br>
Cc: <br>
Date: Tue, 30 Oct 2012 11:00:53 +0100<br>
Subject: Re: [TIP] Testing optparse with Nosetests<br>
Just a follow-up.
<div><br>
</div>
<div>If I add the options that I use with nosetests
(--with-coverage --verbose
--cover-package=mypackage) to my own optparser it
works as expected.</div>
<div><br>
</div>
<div>I don't understand this, and preferably I don't
need those dependencies in my main application..</div>
<div><br>
<div class="gmail_quote">On Tue, Oct 30, 2012 at
9:42 AM, Tim Aerdts <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:fragger123@gmail.com"
target="_blank">fragger123@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0
0 .8ex;border-left:1px #ccc
solid;padding-left:1ex">
Hello,
<div><br>
</div>
<div>Posting this here because it seems more
active then the Nosetests users list.</div>
<div>Anyway I am in the process of writing an
application which makes use of Optparse. I'm
running the tests with Nosetests but I fear
these two might be interfering?</div>
<div><br>
</div>
<div>When I run parser.parse_args() anywhere in
my code Nosetests bugs out.</div>
<div><br>
</div>
<div>
<div>Usage: nosetests [options]</div>
<div>nosetests: error: no such option:
--with-coverage</div>
<div><br>
</div>
<div>Removing the call to parse_args() and
everything runs fine.</div>
<div><br>
</div>
<div>Cheers,</div>
<span class="HOEnZb"><font color="#888888"><span><font
color="#888888">
<div><br>
</div>
-- <br>
Kind regards,<br>
Tim Aerdts<br>
<a moz-do-not-send="true"
href="http://www.tuimz.nl"
target="_blank">http://www.tuimz.nl</a><br>
</font></span></font></span></div>
<span class="HOEnZb"><font color="#888888">
</font></span></blockquote>
</div>
<span class="HOEnZb"><font color="#888888"><br>
<br clear="all">
<div><br>
</div>
-- <br>
Kind regards,<br>
Tim Aerdts<br>
<a moz-do-not-send="true"
href="http://www.tuimz.nl" target="_blank">http://www.tuimz.nl</a><br>
</font></span></div>
<span class="HOEnZb"><font color="#888888">
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a moz-do-not-send="true"
href="mailto:testing-in-python@lists.idyll.org"
target="_blank">testing-in-python@lists.idyll.org</a><br>
<a moz-do-not-send="true"
href="http://lists.idyll.org/listinfo/testing-in-python"
target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br>
</font></span></blockquote>
</div>
<br>
</div>
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a moz-do-not-send="true"
href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a moz-do-not-send="true"
href="http://lists.idyll.org/listinfo/testing-in-python"
target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
Kind regards,<br>
Tim Aerdts<br>
<a moz-do-not-send="true" href="http://www.tuimz.nl">http://www.tuimz.nl</a><br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
testing-in-python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
<a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>
</pre>
</blockquote>
<br>
</body>
</html>