<div dir="ltr"><div class="markdown-here-wrapper" id="markdown-here-wrapper-750643" style><p style="margin:1.2em 0px!important">Hi Daniel,</p>
<p style="margin:1.2em 0px!important">Sorry I misunderstood your question. You should be able to add user-passable options to your test command as follows:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="language-python" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;white-space:pre;overflow:auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,255);background-repeat:initial initial"><span class="comment" style="color:rgb(153,153,136);font-style:italic"># setup.py</span>
<span class="keyword" style="color:rgb(51,51,51);font-weight:bold">from</span> setuptools <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">import</span> setup
<span class="keyword" style="color:rgb(51,51,51);font-weight:bold">from</span> setuptools.command.test <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">import</span> test <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">as</span> TestCommand

<span class="class" style="color:rgb(68,85,136);font-weight:bold"><span class="keyword" style="color:rgb(51,51,51);font-weight:bold">class</span> <span class="title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">PyTest</span><span class="params">(TestCommand)</span>:</span>
    user_options = [
        <span class="comment" style="color:rgb(153,153,136);font-style:italic"># long option, short option, description</span>
        (<span class="string" style="color:rgb(221,17,68)">&#39;flakes&#39;</span>, <span class="built_in" style="color:rgb(0,134,179)">None</span>, <span class="string" style="color:rgb(221,17,68)">&#39;Use pyflakes&#39;</span>),
        (<span class="string" style="color:rgb(221,17,68)">&#39;coverage&#39;</span>, <span class="string" style="color:rgb(221,17,68)">&#39;C&#39;</span>, <span class="string" style="color:rgb(221,17,68)">&#39;Show coverage statistics&#39;</span>),
    ]

    <span class="function"><span class="keyword" style="color:rgb(51,51,51);font-weight:bold">def</span> <span class="title" style="color:rgb(153,0,0);font-weight:bold">initialize_options</span><span class="params">(self)</span>:</span>
        TestCommand.initialize_options(self)
        self.flakes = <span class="built_in" style="color:rgb(0,134,179)">False</span>
        self.coverage = <span class="built_in" style="color:rgb(0,134,179)">False</span>

    <span class="function"><span class="keyword" style="color:rgb(51,51,51);font-weight:bold">def</span> <span class="title" style="color:rgb(153,0,0);font-weight:bold">finalize_options</span><span class="params">(self)</span>:</span>
        TestCommand.finalize_options(self)
        self.test_args = [<span class="string" style="color:rgb(221,17,68)">&#39;tests&#39;</span>]
        <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">if</span> self.flakes:
            self.test_args.append(<span class="string" style="color:rgb(221,17,68)">&#39;--flakes&#39;</span>)
        <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">if</span> self.coverage:
            self.test_args += [
                <span class="string" style="color:rgb(221,17,68)">&#39;--cov&#39;</span>, <span class="string" style="color:rgb(221,17,68)">&#39;code_directory&#39;</span>, <span class="string" style="color:rgb(221,17,68)">&#39;--cov-report&#39;</span>, <span class="string" style="color:rgb(221,17,68)">&#39;term-missing&#39;</span>]
        self.test_suite = <span class="built_in" style="color:rgb(0,134,179)">True</span>

    <span class="function"><span class="keyword" style="color:rgb(51,51,51);font-weight:bold">def</span> <span class="title" style="color:rgb(153,0,0);font-weight:bold">run_tests</span><span class="params">(self)</span>:</span>
        <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">import</span> pytest
        <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">raise</span> SystemExit(pytest.main(self.test_args))

setup(
    tests_require=[<span class="string" style="color:rgb(221,17,68)">&#39;pytest&#39;</span>],
    cmdclass={<span class="string" style="color:rgb(221,17,68)">&#39;test&#39;</span>: PyTest},
)</code></pre>
<p style="margin:1.2em 0px!important">This would add the ability to run <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">python setup.py test --flakes</code> or <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">python setup.py test --coverage</code>. Make sure you change “code_directory” to the actual directory containing your code.</p>


<p style="margin:1.2em 0px!important">I don’t know if it’s easy to pass-through options specified by the user on the command-line, if that’s what you want. You could definitely munge <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">sys.argv</code>, but at that point I would not use Setuptools’ test facility and just create your own by intercepting control at the beginning of the script. In general, I find distutils and Setuptools a little cumbersome in this area, which is why I use Paver.</p>


<p style="margin:1.2em 0px!important">Hope this helps!</p>
</div><div></div><div></div><div></div></div><div class="gmail_extra"><br clear="all"><div><div><br></div><div>--</div><div>Sean Fisk</div></div>
<br><br><div class="gmail_quote">On Wed, Nov 27, 2013 at 1:35 AM, Daniel Farina <span dir="ltr">&lt;<a href="mailto:daniel@heroku.com" target="_blank">daniel@heroku.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">On Tue, Nov 26, 2013 at 9:12 PM, Sean Fisk &lt;<a href="mailto:sean@seanfisk.com">sean@seanfisk.com</a>&gt; wrote:<br>
&gt; Hi Daniel,<br>
&gt;<br>
&gt; The excellent pytest documentation has a section on Setuptools integration.<br>
&gt; In that example, you would want to write instead:<br>
&gt;<br>
&gt; # ...<br>
&gt; self.test_args = [&#39;--flakes&#39;]<br>
&gt; # ...<br>
<br>
</div>I don&#39;t want a static list of these options: I want the user to be<br>
able to modify them.  I want to have the defaults to be sane (I may<br>
add a few common options) but allow advanced and/or slow use cases<br>
(like coverage generation) to be added by the user.<br>
<br>
In retrospect, I think I can do this by munging sys.argv before<br>
setup() is called, but I am wondering if that is among the better<br>
ways.  It seems rather heavyhanded for setuptools to insist to be<br>
informed a-priori of every single valid option, so I imagine there may<br>
be another way.<br>
</blockquote></div><br></div>