title: Doctest's output different from shell's output
body: <p>Using the same code in a doctest and in the shell yields different outputs.<br>
  I have a function called a() that runs through a few tests.<br>
  Those same tests are used in a doctest (test() ).<br>
  With a() I get OBJECT-BLANKLINE-OBJECT while the test() gives me an error and shows only the first OBJECT.<br>
  Is this a flaw in the doctest module?</p>
  
  <p>Here's the whole file with both a() and test() in the top:</p>
  
  <pre><code>'''
  &gt;&gt;&gt; u1 = User("luis@fc.up.pt", "simples")
  &gt;&gt;&gt; u2 = User("ana@fc.up.pt", "complicada")
  &gt;&gt;&gt; u2.askFriend(u1)
  &gt;&gt;&gt; u1.recvRequest(u2)
  &gt;&gt;&gt; u1.confirmFriend(u2)
  &gt;&gt;&gt; p1 = Post(u1, "O ultimo post", "http://www.wikipedia.org")
  &gt;&gt;&gt; p2 = Post(u2, "A ultima resposta", "http://www.google.com")
  &gt;&gt;&gt; c = Comments()
  &gt;&gt;&gt; c.add(p1)
  &gt;&gt;&gt; c.add(p2)
  &gt;&gt;&gt; f1 = c.search(user="ana@fc.up.pt")
  &gt;&gt;&gt; print(f1)
  A ultima resposta
  http://www.google.com
  0 Gosto, 0 Nao gosto
  &gt;&gt;&gt; f2 = c.search(likes=1)
  &gt;&gt;&gt; print(f2)
  &lt;BLANKLINE&gt;
  &gt;&gt;&gt; f3 = c.search(text='post')
  &gt;&gt;&gt; print(f3)
  O ultimo post
  http://www.wikipedia.org
  0 Gosto, 0 Nao gosto
  &lt;BLANKLINE&gt;
  A ultima resposta
  http://www.google.com
  0 Gosto, 0 Nao gosto
  '''
  
  def test():
      import doctest
      doctest.testmod()
  
  def a():
      u1 = User("luis@fc.up.pt", "simples")
      u2 = User("ana@fc.up.pt", "complicada")
      u2.askFriend(u1)
      u1.recvRequest(u2)
      u1.confirmFriend(u2)
      p1 = Post(u1, "O ultimo post", "http://www.wikipedia.org")
      p2 = Post(u2, "A ultima resposta", "http://www.google.com")
      c = Comments()
      c.add(p1)
      c.add(p2)
      f3 = c.search(text="post")
      print(f3)
  
  import string
  
  class User:
  
      def __init__(self,email,passwd):
          self.email = email
          self.passwd = passwd
          self.name = None
          self.year = None
          self.active = True
          self.recv = [] 
          self.conf = []
          self.setPassword(self.passwd)
  
      def __str__(self):
          if self.name == None and self.active == True:
              return str(self.email) + ':' + 'ativa'
  
          elif self.name != None and self.active == True:
              return str(self.name) + ':' + str(self.email) + ':' + 'ativa'
  
          elif self.name != None and self.active == False:
              return str(self.name) + ':' + str(self.email) + ':' + 'inativa'
  
          else:
              return str(self.email) + ':' + 'inativa'
  
      def getEmail(self):
          return self.email
  
      def setPassword(self,passwd):
          abc = string.ascii_lowercase
          cifra = abc[3:] + abc[:3]
          dec = list(passwd)
          passwdCif = ""
          for i in dec:
              cif = cifra[abc.find(i)]
              passwdCif += cif
          self.passwd = passwdCif
  
      def getPassword(self):
          return self.passwd
  
      def setName(self,name):
          self.name = name
  
      def getName(self):
          return self.name
  
      def setBirth(self,year,month,day):
          self.year = year
          self.month = month
          self.day = day
  
      def getBirth(self):
          if self.year == None:
              return None
          else:
              return '(' + str(self.year) + ', ' + str(self.month) + ', ' + str(self.day) + ')'
  
      def isActive(self):
          if self.active == True:
              return True
          else:
              return False
  
      def setActive(self):
          self.active = True
  
      def setInactive(self):
          self.active = False
  
      def askFriend(self,u):
          self.conf.append(u)
  
      def recvRequest(self,u):
          self.recv.append(u)
  
      def confirmFriend(self,u):
          if len(self.recv) == 0:
              return None
          else:
              for i in self.recv:
                  if i == u:
                      self.recv.remove(i)
                      self.conf.append(i)
                  else:
                      return None
  
  
      def isFriend(self,u):
          if u in self.conf:
              return True
          elif self == u:
              return True
          else:
              return False
  
      def showPending(self):
          if len(self.recv) == 0:
              return None
          else:
              for i in self.recv:
                  print i
  
      def showFriends(self):
          if len(self.conf) == 0:
              return None
          else:
              for i in self.conf:
                  print i
  
  class Post():
      def __init__(self,u,text='',link=None):
          self.u = u
          self.text = text
          self.link = link
          self.seg = None
          self.ant = None
          self.likeList = []
          self.dislikeList = []
  
      def __str__(self):
          if self.link == None:
              return str(self.text) + '\n' + str(len(self.likeList)) + ' Gosto, ' + str(len(self.dislikeList)) + ' Nao gosto'
          else:
              return str(self.text) + '\n' + str(self.link) + '\n' + str(len(self.likeList)) + ' Gosto, ' + str(len(self.dislikeList)) + ' Nao gosto'
  
      def updateText(self,text):
          self.text = text
  
      def updateLink(self,link):
          self.link = link
  
      def like(self,u):
          if (u in self.u.conf) or (u == self.u):
              if u in self.dislikeList:
                  self.dislikeList.remove(u)
                  self.likeList.append(u)
              elif u in self.likeList:
                  return None
              else:
                  self.likeList.append(u)
          else:
              return None
  
      def dislike(self,u):
          if (u in self.u.conf) or (u == self.u):
              if u in self.likeList:
                  self.likeList.remove(u)
                  self.dislikeList.append(u)
              elif u in self.dislikeList:
                  return None
              else:
                  self.dislikeList.append(u)
          else:
              return None
  
  class Comments():
      def __init__(self, u=None, text='', link=None):
          self.u = u
          self.text = text
          self.link = link
          self.topo = None
          self.fim = None
  
      def __str__(self):
          actual = self.topo
          s = ''
          if actual == None:
              return ''
          while actual != None:
              if actual.seg == None:
                  s += str(actual)
                  actual = actual.seg
              elif actual.seg != None:
                  s += str(actual) + '\n' + '\n'
                  actual = actual.seg
          return s
  
      def add(self,comment):
          if self.topo == None:
              comment.ant = None
              comment.seg = None
              self.topo = comment
              self.fim = comment
          else:
              comment.ant = None
              comment.seg = self.topo
              self.topo.ant = comment
              self.topo = comment
  
      def remove(self,comment):
          actual = self.topo
          if (self.topo == self.fim) and (self.topo == comment):
              self.topo = None
              self.fim = None
              actual = None
          while actual!=None:
              if actual == comment:
                  if actual.ant == None:
                      self.topo = actual.seg
                      actual.seg.ant = None
                  elif actual.seg == None:
                      self.fim = actual.ant
                      actual.ant.seg = None
                  else:
                      actual.seg.ant = actual.ant
                      actual.ant.seg = actual.seg
                  break
              else:
                  actual = actual.seg
  
      def countLike(self):
          count = 0
          actual = self.topo
          while actual != None:
              if len(actual.likeList) &gt;= 1:
                  count += 1
                  actual = actual.seg
              else:
                  actual = actual.seg
          return count
  
      def showRecentComments(self,n):
          count = 1
          actual = self.topo
          sC = ''
          if actual == None:
              return None
          while actual != None:
              if count &lt; n:
                  if actual.seg == None:
                      sC += str(actual)
                      count += 1
                      actual = actual.seg
                  else:
                      sC += str(actual) + '\n' + '\n'
                      count += 1
                      actual = actual.seg
              elif count == n:
                  sC += str(actual)
                  count += 1
                  actual = actual.seg
              elif count &gt; n:
                  break 
          print sC
  
      def search(self, user=None, likes=None, dislikes=None, text=None):
          result = []
          actual = self.topo
          cR = Comments()
          if actual == None:
              return None
  
          while actual != None:
              if user != None:
                  if actual.u.email != user:
                      actual = actual.seg
                  elif actual.u.email == user:
                      result.append(actual)
                      actual = actual.seg
              elif user == None:
                  break
          actual = self.topo
  
          while actual != None:
              if likes != None:
                  if likes &gt; len(actual.likeList):
                      actual = actual.seg
                  elif likes &lt;= len(actual.likeList):
                      if actual in result:
                          actual = actual.seg
                      else:
                          result.append(actual)
                          actual = actual.seg
              elif likes == None:
                  break
          actual = self.topo
  
          while actual != None:
              if dislikes != None:
                  if dislikes &gt; len(actual.dislikeList):
                      actual = actual.seg
                  elif dislikes &lt;= len(actual.dislikeList):
                      if actual in result:
                          actual = actual.seg
                      else:
                          result.append(actual)
                          actual = actual.seg
              elif dislikes == None:
                  break
          actual = self.topo
  
          while actual != None:
              if text != None:
                  if text not in actual.text:
                      actual = actual.seg
                  elif text in actual.text:
                      if actual in result:
                          actual = actual.seg
                      else:
                          result.append(actual)
                          actual = actual.seg
              elif text == None:
                  break
          if len(result) != 0:
              for i in result:
                  cR.add(i)
          return cR
  </code></pre>
  
  <p>And here's the output I get using both a() and test():</p>
  
  <pre><code>&gt;&gt;&gt; a()
  O ultimo post
  http://www.wikipedia.org
  0 Gosto, 0 Nao gosto
  
  A ultima resposta
  http://www.google.com
  0 Gosto, 0 Nao gosto
  &gt;&gt;&gt; test()
  **********************************************************************
  File "__main__", line 22, in __main__
  Failed example:
      print(f3)
  Expected:
      O ultimo post
      http://www.wikipedia.org
      0 Gosto, 0 Nao gosto
      &lt;BLANKLINE&gt;
      A ultima resposta
      http://www.google.com
      0 Gosto, 0 Nao gosto
  Got:
      A ultima resposta
      http://www.google.com
      0 Gosto, 0 Nao gosto
  **********************************************************************
  1 items had failures:
     1 of  16 in __main__
  ***Test Failed*** 1 failures.
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>I'd also like to apologize for my previous badly asked question.<br>
  Hopefully this one will help me and others.</p>