test_testing.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import warnings
  2. import pytest
  3. import matplotlib.pyplot as plt
  4. from matplotlib.testing.decorators import check_figures_equal
  5. @pytest.mark.xfail(
  6. strict=True, reason="testing that warnings fail tests"
  7. )
  8. def test_warn_to_fail():
  9. warnings.warn("This should fail the test")
  10. @pytest.mark.parametrize("a", [1])
  11. @check_figures_equal(extensions=["png"])
  12. @pytest.mark.parametrize("b", [1])
  13. def test_parametrize_with_check_figure_equal(a, fig_ref, b, fig_test):
  14. assert a == b
  15. def test_wrap_failure():
  16. with pytest.raises(ValueError, match="^The decorated function"):
  17. @check_figures_equal()
  18. def should_fail(test, ref):
  19. pass
  20. @pytest.mark.xfail(raises=RuntimeError, strict=True,
  21. reason='Test for check_figures_equal test creating '
  22. 'new figures')
  23. @check_figures_equal()
  24. def test_check_figures_equal_extra_fig(fig_test, fig_ref):
  25. plt.figure()
  26. @check_figures_equal()
  27. def test_check_figures_equal_closed_fig(fig_test, fig_ref):
  28. fig = plt.figure()
  29. plt.close(fig)