diff --git a/tests/guile.scm b/tests/guile.scm
index f002b3f811f2645c18b5c3aee833c4e60cd8d555..cddd2bed0cafb27476fae4fa3e686f09d26c099c 100644
--- a/tests/guile.scm
+++ b/tests/guile.scm
@@ -1,5 +1,5 @@
 ;;; Guix-kernel -- Guix kernel for Jupyter
-;;; Copyright (C) 2019, 2021 Inria
+;;; Copyright (C) 2019, 2021, 2024 Inria
 ;;;
 ;;; This program is free software: you can redistribute it and/or modify
 ;;; it under the terms of the GNU General Public License as published by
@@ -35,6 +35,10 @@
 
 (define %kernel-key "secretkey")
 
+(define (type-predicate type)
+  (lambda (message)
+    (string=? (message-type message) type)))
+
 
 (test-begin "guile")
 
@@ -68,10 +72,6 @@
   (let ((connection client (allocate-connection %client-context
                                                 "tcp" "127.0.0.1"
                                                 %kernel-key)))
-    (define (type-predicate type)
-      (lambda (message)
-        (string=? (message-type message) type)))
-
     (define (client-thunk)
       (let ((request (message (header "execute_request" "luser" "12345")
                               (scm->json-string
@@ -108,10 +108,6 @@
   (let ((connection client (allocate-connection %client-context
                                                 "tcp" "127.0.0.1"
                                                 %kernel-key)))
-    (define (type-predicate type)
-      (lambda (message)
-        (string=? (message-type message) type)))
-
     (define (client-thunk)
       (let ((request (message (header "execute_request" "luser" "12345")
                               (scm->json-string