Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>doctest</code> is meant to run python code, so you have to do a conversion somewhere. If you are determined to test the commandline interface directly via <code>doctest</code>, one possibility is to do a regexp substitution to <code>__doc__</code> before you pass it to <code>argparse</code>, to take out the <code>os.popen</code> wrapper:</p> <pre><code>clean = re.sub(r"^&gt;&gt;&gt; os\.popen\('(.*)'\).*", r"% \1", __doc__) p = ArgumentParser(description=clean, ...) </code></pre> <p>(Of course there are all sorts of nicer ways to do that, depending on what you consider "nice"). </p> <p>That'll clean it up for the end user. If you also want it to look cleaner in the source, you can go the other way: Put commandline examples in the docstring and don't use doctest.testmodule(). Run your docstring through <code>doctest.script_from_examples</code> and post-process it to insert the <code>os</code> calls. (Then you'll have to embed it into something so you can test it with <code>run_docstring_examples</code>.) <code>doctest</code> doesn't care if the input is valid python, so you can do the following:</p> <pre><code>&gt;&gt;&gt; print doctest.script_from_examples(""" Here is a commandline example I want converted: &gt;&gt;&gt; add -n 3 4 7 """) # Here is a commandline example I want converted: add -n 3 4 # Expected: ## 7 </code></pre> <p>This will still expose the python prompt <code>&gt;&gt;&gt;</code> in the help. If this bothers you, you may just have to process the string in both directions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload