← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~jugmac00/launchpad:how-to-update-configuration-for-testing into launchpad:master

 

Jürgen Gmach has proposed merging ~jugmac00/launchpad:how-to-update-configuration-for-testing into launchpad:master.

Commit message:
Add / update information on how to modify configuration for testing

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jugmac00/launchpad/+git/launchpad/+merge/420153
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/launchpad:how-to-update-configuration-for-testing into launchpad:master.
diff --git a/configs/README.txt b/configs/README.txt
index 9935d94..7849168 100644
--- a/configs/README.txt
+++ b/configs/README.txt
@@ -126,6 +126,9 @@ the config.
     >>> config.answertracker.email_domain
     'answers.launchpad.net'
 
+Please note that TestCase.pushConfig is the preferred way of modifying
+the configuration for testing, also see
+https://launchpad.readthedocs.io/en/latest/.
 
 lazr.conf schema and confs
 --------------------------
diff --git a/doc/how-to/update-configuration-for-testing.rst b/doc/how-to/update-configuration-for-testing.rst
new file mode 100644
index 0000000..8cf49a8
--- /dev/null
+++ b/doc/how-to/update-configuration-for-testing.rst
@@ -0,0 +1,23 @@
+Updating the global configuration for tests
+===========================================
+
+
+Launchpad's configuration is kept in a singleton instance of
+``LaunchpadConfig``, and is available via
+``from lp.services.config import config`` for production code.
+
+``TestCase`` offers a convenience method to set or update values for testing.
+
+.. code-block:: python
+
+    class TestExample(TestCase):
+
+        def setUp(self):
+            self.pushConfig(
+                section="artifactory",
+                base_url="canonical.artifactory.com",
+                read_credentials="user:pass",
+            )
+
+``TestCase.pushConfig`` expects the section name as a string, and the keys and values
+as keyword arguments.
diff --git a/doc/index.rst b/doc/index.rst
index 88a0dce..e8d2632 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -38,6 +38,7 @@ How-to Guides
    how-to/resurrect-dogfood
    how-to/preserve-query-count
    how-to/land-update-for-loggerhead
+   how-to/update-configuration-for-testing
 
 Explanation
 ===========