summaryrefslogtreecommitdiff
path: root/docs/narr/testing.rst
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-10-08 17:34:43 -0400
committerChris McDonough <chrism@plope.com>2012-10-08 17:34:43 -0400
commit2aed2c783a99efaa48b145d174347c9512e40c5a (patch)
tree11ab8f12072353e7e324e66bda5914c78cd5c1ea /docs/narr/testing.rst
parenta9f5e705bb331098946eef774857511a02e4f498 (diff)
parent1273d56ee5c038f447dce0525844cd3ea6c15e4d (diff)
downloadpyramid-2aed2c783a99efaa48b145d174347c9512e40c5a.tar.gz
pyramid-2aed2c783a99efaa48b145d174347c9512e40c5a.tar.bz2
pyramid-2aed2c783a99efaa48b145d174347c9512e40c5a.zip
Merge branch 'master' of github.com:Pylons/pyramid
Diffstat (limited to 'docs/narr/testing.rst')
-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?
~~~~~