Can python doctest ignore some output lines?

后端 未结 6 1606
灰色年华
灰色年华 2020-12-09 15:16

I\'d like to write a doctest like this:

\"\"\"
>>> print a.string()
          foo : a
          bar : b
         date : 

        
6条回答
  •  悲哀的现实
    2020-12-09 15:46

    Ignoring the whole line is bit tricky though. Here:

    """
    >>> do_your_thing() #doctest:+ELLIPSIS
    ...
    """
    

    The triple dot will be interpreted as line continuation, and cause a syntax error.

    If you want to ignore the whole line, you'll need something like:

    """
    >>> sys.stdout.write('skip from here '); do_your_thing() #doctest:+ELLIPSIS
    skip from here ...
    """
    

提交回复
热议问题