diff --git a/gdb/testsuite/gdb.python/tui-window-factory.exp b/gdb/testsuite/gdb.python/tui-window-factory.exp
index 3e898d01c7ba2f8b967cca74076f22010c63ac0b..e3b403bdea071fb0a4148dc8e4c97369db5c92b3 100644
--- a/gdb/testsuite/gdb.python/tui-window-factory.exp
+++ b/gdb/testsuite/gdb.python/tui-window-factory.exp
@@ -32,7 +32,10 @@ set pyfile [gdb_remote_download host \
 		${srcdir}/${subdir}/${gdb_test_file_name}.py]
 
 Term::clean_restart 24 80
-Term::prepare_for_tui
+if { ![Term::prepare_for_tui] } {
+    unsupported "TUI not supported"
+    return
+}
 
 gdb_test "source ${pyfile}" "Python script imported" \
     "import python scripts"