diff --git a/t/portrait.t b/t/portrait.t
index 1e7a50db..fb731cc5 100644
--- a/t/portrait.t
+++ b/t/portrait.t
@@ -42,8 +42,11 @@ test_page(update_page('headers', "[new]foo\n== one ==\ntext\n== two ==\ntext\n==
qq{
three},
qq{one
text
},
qq{two
}, );
+
remove_module('toc.pl');
-*RunMyRules = *RunMyRulesTocOld; # so that it can be reloaded safely!
+# The next two are necessary so that toc.pl can be reloaded safely later!
+*ApplyRules = *OldTocApplyRules;
+*RunMyRules = *RunMyRulesTocOld;
remove_rule(\&TocRule);
remove_module('usemod.pl');
remove_rule(\&UsemodRule);