Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>rewrite:</strong> This actually does work now; I realized that the "doctest" I had written earlier was actually not being parsed as the module docstring, so the test wasn't passing: it was just not being run.</p> <p>I made sure to double-check this one.</p> <pre><code>__doc__ = """ &gt;&gt;&gt; L = [] &gt;&gt;&gt; if True: ... append_to(L) # doctest: +IGNORE_RESULT &gt;&gt;&gt; L [1] """.replace('+IGNORE_RESULT', '+ELLIPSIS\n&lt;...&gt;') def append_to(L): L.append(1) class A(object): pass return A() </code></pre> <p>I'm not sure if this qualifies as more readable or not. Note that there's nothing special about <code>&lt;...&gt;</code>: it will only work if the actual return value has that form, as it does in this case (i.e. it's <code>&lt;module.A object at 0x...&gt;</code>). The ELLIPSIS option makes <code>...</code> "match any <strong>substring</strong> in the actual output" <a href="http://docs.python.org/library/doctest.html#doctest.ELLIPSIS" rel="nofollow">¹</a>. So I don't think there's a way to get it to match the entirety of the output.</p> <p><strong>update:</strong> To do this the "proper" way, it looks like you'd want to call <a href="http://docs.python.org/library/doctest.html#doctest.register_optionflag" rel="nofollow"><code>doctest.register_optionflag('IGNORE_RESULT')</code></a>, subclass <a href="http://docs.python.org/library/doctest.html#doctest.OutputChecker" rel="nofollow"><code>doctest.OptionChecker</code></a>, and arrange for an instance of that subclass to be used by the doctest. Presumably this means that running your doctest via <code>$ python -m doctest your_module.py</code> is not an option.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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