Skip to content

Commit

Permalink
Added new IGNORE_OUTPUT flags for doctests. This is useful in cases w…
Browse files Browse the repository at this point in the history
…here we want the doctest to *run* (maybe later doctests on the same page depend on this code running), but we don't care *exactly* what the output is (maybe the output differs slightly between platforms, but in ways we aren't concerned about testing)
  • Loading branch information
embray committed Dec 1, 2015
1 parent ae3c105 commit 1413643
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions astropy/tests/output_checker.py
Expand Up @@ -18,6 +18,7 @@

FIX = doctest.register_optionflag('FIX')
FLOAT_CMP = doctest.register_optionflag('FLOAT_CMP')
IGNORE_OUTPUT = doctest.register_optionflag('IGNORE_OUTPUT')


class AstropyOutputChecker(doctest.OutputChecker):
Expand Down Expand Up @@ -149,6 +150,9 @@ def normalize_floats(self, want, got, flags):
return False

def check_output(self, want, got, flags):
if flags & IGNORE_OUTPUT:
return True

if flags & FIX:
want, got = self.do_fixes(want, got)

Expand Down
13 changes: 13 additions & 0 deletions docs/development/testguide.rst
Expand Up @@ -870,6 +870,19 @@ traceback is skipped in the example output--only the first and last lines
of the output are checked. See the :mod:`doctest` documentation for
more examples of skipping output.

Ignoring all output
^^^^^^^^^^^^^^^^^^^

Another possibility for ignoring output is to use the
``# doctest: +IGNORE_OUTPUT`` flag. This allows a doctest to execute (and
check that the code executes without errors), but allows the entire output
to be ignored in cases where we don't care what the output is. This differs
from using ellipses in that we can still provide complete example output, just
without the test checking that it is exactly right. For example::

>>> print('Hello world') # doctest: +IGNORE_OUTPUT
We don't really care what the output is as long as there were no errors...


Handling float output
---------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/units/quantity.rst
Expand Up @@ -90,7 +90,7 @@ feature needs to be explicitly turned on:
.. doctest-requires:: matplotlib

>>> from astropy.visualization import quantity_support
>>> quantity_support()
>>> quantity_support() # doctest: +IGNORE_OUTPUT
<astropy.visualization.units.MplQuantityConverter ...>

Then |quantity| objects can be passed to matplotlib plotting
Expand Down

0 comments on commit 1413643

Please sign in to comment.