Skip to content

Conversation

@Anirudh-kasthuri
Copy link

@Anirudh-kasthuri Anirudh-kasthuri commented Jan 11, 2026

Hey folks,

I noticed that the matplotlib plot directive wasn’t reporting any errors or warnings when the code it runs fails. Basically, it would silently move on, which can be confusing when building docs. This PR fixes that.

What’s changed:

  • Now, if the code inside a plot directive raises a RuntimeWarning (or other errors), Sphinx will catch it and report it properly when using -W.
  • Added/updated the test test_plot_directive_warns_on_failure to make sure this behavior is checked automatically.

How I verified:

  • Ran pytest -k test_plot_directive_warns_on_failure and it passes
  • Built docs with python -m sphinx -b html . _build -W and the warning shows up as expected

This should close #30899. Let me know if anything else is needed or if you spot any edge cases I missed.

@rcomer
Copy link
Member

rcomer commented Jan 11, 2026

Thank you for your contribution. Did you intend to add the _build directory?

@rcomer
Copy link
Member

rcomer commented Jan 11, 2026

I’m going to put this in draft for now. Overall it does not look like you pushed what you intended

  1. added _build directory
  2. no change in the plot directive module
  3. the new test is failing, likely because of 2

Please mark this as "ready for review" when you are ready. In the meantime, if you need help, feel free to ask questions here. Or you may prefer to ask them in our incubator chat channel.

@rcomer rcomer marked this pull request as draft January 11, 2026 20:27
@Anirudh-kasthuri Anirudh-kasthuri marked this pull request as ready for review January 12, 2026 05:19
@Anirudh-kasthuri
Copy link
Author

Thanks for the review!

I’ve pushed an update that ensures failures inside the plot directive are surfaced as proper warnings instead of being silently ignored.

I verified the behavior locally using python -m sphinx -W on a minimal Sphinx project and confirmed that execution failures now produce warnings as expected.

Please let me know if you’d like me to add a regression test in test_sphinxext.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: plot_directive does not raise warning or error when the code it runs fails

3 participants