From a7ab5420aa2bb3441fe0f03c51b44b5334997189 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 21 Jan 2014 13:28:20 +0100 Subject: [PATCH] Document configuration variables edits in unit tests. --- develop/advanced_plugin_testing.rst | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/develop/advanced_plugin_testing.rst b/develop/advanced_plugin_testing.rst index 78c87f1..2e69020 100644 --- a/develop/advanced_plugin_testing.rst +++ b/develop/advanced_plugin_testing.rst @@ -200,6 +200,37 @@ testing for some reason, we could just do this:: And now you can be assured that supybot.commands.nested is going to be off for all of your test methods in this test case class. +Temporaly setting a configuration variable +------------------------------------------ + +Sometimes we want to change a configuration variable only in a test (or in +a part of a test), and keep the original value for other tests. The +historical way to do it is:: + + import supybot.conf as conf + + class MyPluginTestCase(PluginTestCase): + def testThisThing(self): + original_value conf.supybot.commands.nested() + conf.supybot.commands.nested.setValue(False) + try: + # stuff + finally: + conf.supybot.commands.nested.setValue(original_value) + +But there is a more compact syntax, using context managers:: + + import supybot.conf as conf + + class MyPluginTestCase(PluginTestCase): + def testThisThing(self): + with conf.supybot.commands.nested.context(False): + # stuff + +.. note:: + Until stock Supybot or Gribble merge the second syntax, only Limnoria + will support it. + Plugin Test Methods =================== The full list of test methods and how to use them.