Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qtconsole breaks doctest.testmod() in Python 3.3 #3091

Closed
onesandzeroes opened this issue Mar 27, 2013 · 1 comment
Closed

qtconsole breaks doctest.testmod() in Python 3.3 #3091

onesandzeroes opened this issue Mar 27, 2013 · 1 comment
Milestone

Comments

@onesandzeroes
Copy link
Contributor

Ipython version: 0.13.1

Python version: Python 3.3.0 (default, Mar 8 2013, 07:01:05)

When using the qtconsole, I don't seem to be able to use doctest.testmod(), as I get errors about how "'OutStream' object has no attribute 'encoding'". To demonstrate the problem, I created doctest_example.py:

def my_function(x, y):
    """
    Adds x and y

    >>> my_function(3, 5)
    8
    """
    return x + y

if __name__ == '__main__':
    import doctest
    doctest.testmod()

Running this with %run doctest_example.py in the QtConsole results in the error message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/lib/python3/dist-packages/IPython/utils/py3compat.py in execfile(fname, glob, loc)
     74     def execfile(fname, glob, loc=None):
     75         loc = loc if (loc is not None) else glob
---> 76         exec(compile(open(fname, 'rb').read(), fname, 'exec'), glob, loc)
     77 
     78     # Refactor print statements in doctests.

/home/marius/Programming/NLP/Assignment2/doctest_example.py in <module>()
     10 if __name__ == '__main__':
     11     import doctest
---> 12     doctest.testmod()

/usr/lib/python3.3/doctest.py in testmod(m, name, globs, verbose, report, optionflags, extraglobs, raise_on_error, exclude_empty)
   1904 
   1905     for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
-> 1906         runner.run(test)
   1907 
   1908     if report:

/usr/lib/python3/dist-packages/IPython/utils/doctestreload.py in f(*a, **k)
     35         sys.displayhook = sys.__displayhook__
     36         try:
---> 37             out = func(*a,**k)
     38         finally:
     39             sys.displayhook = dhook_s

/usr/lib/python3.3/doctest.py in run(self, test, compileflags, out, clear_globs)
   1398         save_stdout = sys.stdout
   1399         if out is None:
-> 1400             encoding = save_stdout.encoding
   1401             if encoding is None or encoding.lower() == 'utf-8':
   1402                 out = save_stdout.write

AttributeError: 'OutStream' object has no attribute 'encoding'

The error doesn't seem to go away when toggling %doctest_mode.

@minrk
Copy link
Member

minrk commented Mar 27, 2013

Should be fixed by #2500, which has been backported to 0.13.2, which should be out soon.

@minrk minrk closed this as completed Mar 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants