title: Python doctest: skip a test conditionally
body: <p>I know how to skip a doctest using <code># doctest: +SKIP</code>, but I can't figure out how to skip a test <em>sometimes</em>, based on a runtime condition.  For example:</p>
  
  <pre><code>&gt;&gt;&gt; if os.path.isfile("foo"):
  ...    open("foo").readlines()
  ... else:
  ...    pass # doctest: +SKIP
  ['hello', 'world']
  </code></pre>
  
  <p>That's the sort of thing I want to do.  I would also accept a solution which runs the test, but changes the expected result to an exception with traceback if the condition is not met (i.e. run the test unconditionally but modify the expected result).</p>