diff options
| author | Brian Sutherland <brian@vanguardistas.net> | 2012-06-16 12:57:46 +0200 |
|---|---|---|
| committer | Brian Sutherland <brian@vanguardistas.net> | 2012-06-16 12:58:20 +0200 |
| commit | fbbb20c7953370c86f999e865b1a9d682690eb70 (patch) | |
| tree | d5417bb0cbad8b5889fcb18a2089a6908fa1f7af /docs | |
| parent | eb3c87230402201669501d5889d43634b785a9ed (diff) | |
| download | pyramid-fbbb20c7953370c86f999e865b1a9d682690eb70.tar.gz pyramid-fbbb20c7953370c86f999e865b1a9d682690eb70.tar.bz2 pyramid-fbbb20c7953370c86f999e865b1a9d682690eb70.zip | |
A context manager for test setup
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/api/testing.rst | 2 | ||||
| -rw-r--r-- | docs/narr/testing.rst | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/docs/api/testing.rst b/docs/api/testing.rst index f388dc263..1366a1795 100644 --- a/docs/api/testing.rst +++ b/docs/api/testing.rst @@ -9,6 +9,8 @@ .. autofunction:: tearDown + .. autofunction:: testConfig(registry=None, request=None, hook_zca=True, autocommit=True, settings=None) + .. autofunction:: cleanUp .. autoclass:: DummyResource diff --git a/docs/narr/testing.rst b/docs/narr/testing.rst index 5ce2c8a66..89bc1a089 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? ~~~~~ |
