How to set argparse arguments from python script
<p>I have a <code>main</code> function specified as entry point in my package's <code>setup.py</code> which uses the <code>argparse</code> package in order to pass command line arguments (see <a href="http://stackoverflow.com/questions/2853088/setuptools-not-passing-arguments-for-entry-points">discussion here</a>):</p>

<pre><code># file with main routine specified as entry point in setup.py
import argparse
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('a', type=str, help='mandatory argument a')
    args = parser.parse_args()
</code></pre>

<p>Ideally, I would like to use the same <code>main</code> function in the package's tests as suggested <a href="http://python-packaging.readthedocs.io/en/latest/command-line-scripts.html" rel="nofollow">here</a>. In the latter context, I would like to call the <code>main</code> function from within the test class and set (some of) the command line arguments prior to the function call (which otherwise will fail, due to missing arguments).</p>

<pre><code># file in the tests folder calling the above main function
class TestConsole(TestCase):
    def test_basic(self):
        set_value_of_a()
        main()
</code></pre>

<p>Is that possible?</p>

<p>Add <code>kwargs</code> to <code>main</code> and if they're <code>None</code>, you set them to the <code>parse_args</code>.</p>

python argparse setup.py entry-point