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

Skip to content

Commit baf4c3f

Browse files
committed
TST: add headless-fallback success test case, and rename existing failure case
1 parent f45707d commit baf4c3f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/matplotlib/tests/test_rcparams.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,11 @@ def test_rcparams_reset_after_fail():
521521

522522

523523
@pytest.mark.skipif(sys.platform != "linux", reason="Linux only")
524-
def test_backend_fallback_headless(tmp_path):
524+
def test_backend_fallback_headless_invalid_backend(tmp_path):
525525
env = {**os.environ,
526526
"DISPLAY": "", "WAYLAND_DISPLAY": "",
527527
"MPLBACKEND": "", "MPLCONFIGDIR": str(tmp_path)}
528+
# plotting should fail with the tkagg backend selected in a headless environment
528529
with pytest.raises(subprocess.CalledProcessError):
529530
subprocess_run_for_testing(
530531
[sys.executable, "-c",
@@ -536,6 +537,20 @@ def test_backend_fallback_headless(tmp_path):
536537
env=env, check=True, stderr=subprocess.DEVNULL)
537538

538539

540+
@pytest.mark.skipif(sys.platform != "linux", reason="Linux only")
541+
def test_backend_fallback_headless_auto_backend(tmp_path):
542+
env = {**os.environ,
543+
"DISPLAY": "", "WAYLAND_DISPLAY": "",
544+
"MPLBACKEND": "", "MPLCONFIGDIR": str(tmp_path)}
545+
# plotting should succeed using auto-backend selection in a headless environment
546+
subprocess_run_for_testing(
547+
[sys.executable, "-c",
548+
"import matplotlib.pyplot;"
549+
"matplotlib.pyplot.plot(42);"
550+
],
551+
env=env, check=True, stderr=subprocess.DEVNULL)
552+
553+
539554
@pytest.mark.skipif(
540555
sys.platform == "linux" and not _c_internal_utils.xdisplay_is_valid(),
541556
reason="headless")

0 commit comments

Comments
 (0)