test_backend_webagg.py 702 B

123456789101112131415161718192021222324252627
  1. import subprocess
  2. import os
  3. import sys
  4. import pytest
  5. @pytest.mark.parametrize("backend", ["webagg", "nbagg"])
  6. def test_webagg_fallback(backend):
  7. pytest.importorskip("tornado")
  8. if backend == "nbagg":
  9. pytest.importorskip("IPython")
  10. env = dict(os.environ)
  11. if os.name != "nt":
  12. env["DISPLAY"] = ""
  13. env["MPLBACKEND"] = backend
  14. test_code = (
  15. "import os;"
  16. + f"assert os.environ['MPLBACKEND'] == '{backend}';"
  17. + "import matplotlib.pyplot as plt; "
  18. + "print(plt.get_backend());"
  19. f"assert '{backend}' == plt.get_backend().lower();"
  20. )
  21. ret = subprocess.call([sys.executable, "-c", test_code], env=env)
  22. assert ret == 0