Doctests that contain string literals

后端 未结 1 736
走了就别回头了
走了就别回头了 2021-02-10 23:10

I have a unit test that I\'d like to write for a function that takes XML as a string. It\'s a doctest and I\'d like the XML in-line with the tests. Since the XML is multi-line

1条回答
  •  粉色の甜心
    2021-02-11 00:00

    This code works, e.g. with Python 2.7.12 and 3.5.2:

    def test():
      """
      >>> config = '''
      ... 
      ...   d1
      ...   d2
      ... '''
      >>> print(config)
      
      
        d1
        d2
      
    
      """
    
    if __name__ == "__main__":
      import doctest
    doctest.testmod(name='test')
    

    0 讨论(0)
提交回复
热议问题