Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Consider adding a sphinx_gallery_expected_error code-block option to show an expected error #912

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

Open
smarie opened this issue Feb 3, 2022 · 2 comments · May be fixed by #930
Open

Consider adding a sphinx_gallery_expected_error code-block option to show an expected error #912

smarie opened this issue Feb 3, 2022 · 2 comments · May be fixed by #930

Comments

@smarie
Copy link

smarie commented Feb 3, 2022

( From smarie/mkdocs-gallery#23 )

Sometimes we write a code block to show the reader that something raises an error.
It is a bit tideous to have to try/catch this error to prevent sphinx-gallery to fail with Unexpected failing examples.
Still, in this situation we do not as well want to fail the rest of the example, nor mark the whole file as expected to fail.

It would be much better to be able to say that we expect it at a block level:

"""
Example
=======

The following code raises an error
"""
# sphinx_gallery_expected_error
1 + "hello"

# %%
# But this works:

1 * "hello"

We could maybe have a sphinx_gallery_expected_error similar to the sphinx_gallery_defer_figures configuration.
It could even accept an optional argument (the exception type, as in pytest.raises) to avoid being too tolerant.

@larsoner
Copy link
Contributor

larsoner commented Feb 3, 2022

Agreed this would be useful. @smarie do you want to try implementing this?

@smarie
Copy link
Author

smarie commented Feb 4, 2022

I will see if I can find an hour next week. If not that will have to wait one or two more weeks - holidays ahead ;)

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

Successfully merging a pull request may close this issue.

2 participants