title: ValueError: wrapper loop when unwrapping
body: <p>Python3 test cases (doctests) are failing with my sample code. But the same is working fine in Python2.</p>
  
  <p><code>test.py</code></p>
  
  <pre><code>class Test(object):
      def __init__(self, a=0):
          self.a = a
  
      def __getattr__(self, attr):
          return Test(a=str(self.a) + attr)
  </code></pre>
  
  <p><code>tst.py</code></p>
  
  <pre><code>from test import Test
  
  t = Test()
  </code></pre>
  
  <p>Run test cases: <code>python3 -m doctest -v tst.py</code></p>
  
  <p>Error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
      "__main__", mod_spec)
    File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
      exec(code, run_globals)
    File "/usr/lib/python3.6/doctest.py", line 2787, in &lt;module&gt;
      sys.exit(_test())
    File "/usr/lib/python3.6/doctest.py", line 2777, in _test
      failures, _ = testmod(m, verbose=verbose, optionflags=options)
    File "/usr/lib/python3.6/doctest.py", line 1950, in testmod
      for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
    File "/usr/lib/python3.6/doctest.py", line 933, in find
      self._find(tests, obj, name, module, source_lines, globs, {})
    File "/usr/lib/python3.6/doctest.py", line 992, in _find
      if ((inspect.isroutine(inspect.unwrap(val))
    File "/usr/lib/python3.6/inspect.py", line 513, in unwrap
      raise ValueError('wrapper loop when unwrapping {!r}'.format(f))
  ValueError: wrapper loop when unwrapping &lt;test.Test object at 0x7f6e80028550&gt;
  </code></pre>
  
  <p>Can anyone please help in how to overcome this error.</p>
  
  <p>Thanks.</p>