diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim
index e43dd8d94471b869270442a32af37602bb05cacb..2ef0f554fe792f6eb8a1dc5fcade0a2b6c3ce670 100644
--- a/src/testdir/runtest.vim
+++ b/src/testdir/runtest.vim
@@ -13,6 +13,9 @@
 " For csh:
 "     setenv TEST_FILTER Test_channel
 "
+" If the environment variable $TEST_SKIP_PAT is set then test functions
+" matching this pattern will be skipped.  It's the opposite of $TEST_FILTER.
+"
 " While working on a test you can make $TEST_NO_RETRY non-empty to not retry:
 "     export TEST_NO_RETRY=yes
 "
@@ -329,13 +332,17 @@ func FinishTesting()
 
   if s:done == 0
     if s:filtered > 0
-      let message = "NO tests match $TEST_FILTER: '" .. $TEST_FILTER .. "'"
+      if $TEST_FILTER != ''
+        let message = "NO tests match $TEST_FILTER: '" .. $TEST_FILTER .. "'"
+      else
+        let message = "ALL tests match $TEST_SKIP_PAT: '" .. $TEST_SKIP_PAT .. "'"
+      endif
     else
       let message = 'NO tests executed'
     endif
   else
     if s:filtered > 0
-      call add(s:messages, "Filtered " .. s:filtered .. " tests with $TEST_FILTER")
+      call add(s:messages, "Filtered " .. s:filtered .. " tests with $TEST_FILTER and $TEST_SKIP_PAT")
     endif
     let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
   endif
@@ -461,6 +468,12 @@ endif
 
 " Execute the tests in alphabetical order.
 for g:testfunc in sort(s:tests)
+  if $TEST_SKIP_PAT != '' && g:testfunc =~ $TEST_SKIP_PAT
+    call add(s:messages, g:testfunc .. ' matches $TEST_SKIP_PAT')
+    let s:filtered += 1
+    continue
+  endif
+
   " Silence, please!
   set belloff=all
   let prev_error = ''
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 11e152407fae617ab31873e33881f7f523e15b2c..9ac4d0b1dd25003db8ccafdf5fd5066447c3690a 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -2832,14 +2832,47 @@ def Test_expr7_namespace()
       assert_equal('some', get(t:, 'some_var', 'xxx'))
       assert_equal('xxx', get(t:, 'no_var', 'xxx'))
       unlet t:some_var
+  END
+  CheckDefAndScriptSuccess(lines)
+enddef
 
+def Test_expr7_namespace_loop_def()
+  var lines =<< trim END
       # check using g: in a for loop more than DO_NOT_FREE_CNT times
+      var exists = 0
+      var exists_not = 0
       for i in range(100000)
         if has_key(g:, 'does-not-exist')
+          exists += 1
+        else
+          exists_not += 1
         endif
       endfor
+      assert_equal(0, exists)
+      assert_equal(100000, exists_not)
   END
-  CheckDefAndScriptSuccess(lines)
+  CheckDefSuccess(lines)
+enddef
+
+" NOTE: this is known to be slow.  To skip use:
+"   :let $TEST_SKIP_PAT = 'Test_expr7_namespace_loop_script'
+def Test_expr7_namespace_loop_script()
+  var lines =<< trim END
+      vim9script
+      # check using g: in a for loop more than DO_NOT_FREE_CNT times
+      var exists = 0
+      var exists_not = 0
+      for i in range(100000)
+        if has_key(g:, 'does-not-exist')
+          exists += 1
+        else
+          exists_not += 1
+        endif
+      endfor
+      assert_equal(0, exists)
+      assert_equal(100000, exists_not)
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 def Test_expr7_parens()
diff --git a/src/version.c b/src/version.c
index 9c374b1647d5cf24a47654036ddf2e7dce483cd3..d31a0199163f68f955deac16b5d815a3ca866b15 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3311,
 /**/
     3310,
 /**/