Can python doctest ignore some output lines?

后端 未结 6 1611
灰色年华
灰色年华 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:47

    With doctest.ELLIPSIS, you can use ... to mean "match any string here". You can set doctest options with a doctest directive, to make it active for just one test case: one example in the online docs is:

    >>> print range(20) # doctest:+ELLIPSIS
    [0, 1, ..., 18, 19]
    

    If you want a doctest option to be active throughout, you can pass it as the optionflags= argument to whatever doctest functions you use, e.g. doctest.testfile. (You can pass multiple option flags there by using the | operator to bit-or them).

提交回复
热议问题