summaryrefslogtreecommitdiff
path: root/docs/narr
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-09-15 19:33:54 -0400
committerChris McDonough <chrism@plope.com>2012-09-15 19:33:54 -0400
commit97150cc540bad56f8ff7760616d75db8894da73b (patch)
treec1ae5b10d93350b1a763eecdb3857d4aa7af92b6 /docs/narr
parenta98f0cf435e31864e632d9105ffdda30aa776212 (diff)
parentd6f0fd56fb93d30d8d7d6b490a57967d940b0135 (diff)
downloadpyramid-97150cc540bad56f8ff7760616d75db8894da73b.tar.gz
pyramid-97150cc540bad56f8ff7760616d75db8894da73b.tar.bz2
pyramid-97150cc540bad56f8ff7760616d75db8894da73b.zip
merge jinty's testConfig code
Diffstat (limited to 'docs/narr')
-rw-r--r--docs/narr/testing.rst24
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/narr/testing.rst b/docs/narr/testing.rst
index 50e9d5604..20017064b 100644
--- a/docs/narr/testing.rst
+++ b/docs/narr/testing.rst
@@ -157,6 +157,30 @@ We use a "dummy" request implementation supplied by
:class:`pyramid.testing.DummyRequest` because it's easier to construct
than a "real" :app:`Pyramid` request object.
+Test setup using a context manager
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+An alternative style of setting up a test configuration is to use the
+`with` statement and :func:`pyramid.testing.testConfig` to create a
+context manager. The context manager will call
+:func:`pyramid.testing.setUp` before the code under test and
+:func:`pyramid.testing.tearDown` afterwards.
+
+This style is useful for small self-contained tests. For example:
+
+.. code-block:: python
+ :linenos:
+
+ import unittest
+
+ class MyTest(unittest.TestCase):
+
+ def test_my_function(self):
+ from pyramid import testing
+ with testing.testConfig() as config:
+ config.add_route('bar', '/bar/{id}')
+ my_function_which_needs_route_bar()
+
What?
~~~~~