diff --git a/src/@dseries/subsref.m b/src/@dseries/subsref.m
index 1b8a4fb40aca4babde9547a2ce2ee2d24facbbf6..b5c101b449f643c113a6bf06b568c1186e26f53f 100644
--- a/src/@dseries/subsref.m
+++ b/src/@dseries/subsref.m
@@ -15,7 +15,7 @@ function r = subsref(o, S) % --*-- Unitary tests --*--
 %                     by applying a public method on `o`, or a dseries object built by extracting
 %                     a variable from `o`, or a dseries object containing a subsample.
 
-% Copyright © 2011-2021 Dynare Team
+% Copyright © 2011-2022 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -488,9 +488,9 @@ return
      t(2) = 0;
  end
  try
-     warning off all
+     warnstate = warning('off');
      c = ts1{'[A-Z]_1'};
-     warning on all
+     warning(warnstate);
      t(3) = 0;
  catch
      t(3) = 1;
diff --git a/tests/runalltests.m b/tests/runalltests.m
index 107be584feb1e18b0e5ff236e4ac3dd534c70a65..d29ab02751d6feb9f2fdc6073a4889def3706842 100644
--- a/tests/runalltests.m
+++ b/tests/runalltests.m
@@ -1,6 +1,6 @@
 function runalltests()
 
-% Copyright © 2015-2019 Dynare Team
+% Copyright © 2015-2022 Dynare Team
 %
 % This code is free software: you can redistribute it and/or modify
 % it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@ catch
     initialize_dseries_class();
 end
 
-warning off
+warnstate = warning('off');
 
 if isoctave()
     if ~user_has_octave_forge_package('io')
@@ -60,7 +60,7 @@ else
     system('touch pass');
 end
 
-warning on
+warning(warnstate);
 path(opath);
 
 display_report(r);