<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 = [&#39;-h&#39;]</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 href="http://www.schrodinger.com/">http://www.schrodinger.com/</a><br><br><div class="gmail_quote">On Tue, Oct 30, 2012 at 12:00 PM,  <span dir="ltr">&lt;<a href="mailto:testing-in-python-request@lists.idyll.org" target="_blank">testing-in-python-request@lists.idyll.org</a>&gt;</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 href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a 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 &#39;help&#39; to<br>
        <a href="mailto:testing-in-python-request@lists.idyll.org">testing-in-python-request@lists.idyll.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:testing-in-python-owner@lists.idyll.org">testing-in-python-owner@lists.idyll.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of testing-in-python digest...&quot;<br>
<br>Today&#39;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 &lt;<a href="mailto:fragger123@gmail.com">fragger123@gmail.com</a>&gt;<br>To: <a href="mailto:testing-in-python@lists.idyll.org">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&#39;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 href="http://www.tuimz.nl" target="_blank">http://www.tuimz.nl</a><br>


</div>
<br><br>---------- Forwarded message ----------<br>From: Tim Aerdts &lt;<a href="mailto:fragger123@gmail.com">fragger123@gmail.com</a>&gt;<br>To: <a href="mailto:testing-in-python@lists.idyll.org">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&#39;t understand this, and preferably I don&#39;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">&lt;<a href="mailto:fragger123@gmail.com" target="_blank">fragger123@gmail.com</a>&gt;</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&#39;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><font color="#888888"><div><br></div>-- <br>Kind regards,<br>Tim Aerdts<br><a href="http://www.tuimz.nl" target="_blank">http://www.tuimz.nl</a><br>




</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Kind regards,<br>Tim Aerdts<br><a href="http://www.tuimz.nl" target="_blank">http://www.tuimz.nl</a><br>
</div>
<br>_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a 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></div>