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

Doc bug? How to check contents of outputs in tests? #8964

Closed
davclark opened this issue Nov 8, 2015 · 3 comments
Closed

Doc bug? How to check contents of outputs in tests? #8964

davclark opened this issue Nov 8, 2015 · 3 comments
Milestone

Comments

@davclark
Copy link
Contributor

davclark commented Nov 8, 2015

For rpy2, it'd be nice to have tests that check for the contents of output cells. Is there a way to do this?

There's too much dynamic code execution around the various run_... functions for me to figure out how to trace through. IPython help (ip.run_cell_magic?) raises a AttributeError! I can't find anything in the docs on testing modules that use IPython either.

@davclark
Copy link
Contributor Author

davclark commented Nov 8, 2015

@minrk minrk added this to the no action milestone Nov 9, 2015
@minrk
Copy link
Member

minrk commented Nov 9, 2015

We use a capture_output context manager in our tests. It separately captures stdout, stderr, and mime-type display outputs:

from IPython.core.interactiveshell import InteractiveShell
from IPython.utils.capture import capture_output

ip = InteractiveShell.instance()

ip.run_cell("""
import sys
from IPython.display import display, HTML
""")
with capture_output() as out:
    ip.run_cell("""
print("hello")
display(HTML("<b>bold</b>"))
print("ERRORED", file=sys.stderr)
""")

assert out.stdout == 'hello\n'
assert out.stderr == 'ERRORED\n'
assert out.outputs[0].data['text/html'] == "<b>bold</b>"

@Carreau
Copy link
Member

Carreau commented Jul 19, 2017

Hi,

This issue has been quiet for almost two years, and I don't think there is anything we can do. It has been marked as no-action, and I'm going to close it to attempt to reduce the number of opened issue. Feel free to reopen if needed.

Thanks.

@Carreau Carreau closed this as completed Jul 19, 2017
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

3 participants