summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-01-12 02:36:10 -0500
committerChris McDonough <chrism@plope.com>2011-01-12 02:36:10 -0500
commitf52d595bd1cef5cb97d440c8ba1b1a9850ec8f4b (patch)
tree054365e174f8707b2bf3d36906e718bbfcbf32de
parent57d300f292b87b67163399db9377fb2920621bd3 (diff)
downloadpyramid-f52d595bd1cef5cb97d440c8ba1b1a9850ec8f4b.tar.gz
pyramid-f52d595bd1cef5cb97d440c8ba1b1a9850ec8f4b.tar.bz2
pyramid-f52d595bd1cef5cb97d440c8ba1b1a9850ec8f4b.zip
Features
-------- - ``pyramid.testing.setUp`` and ``pyramid.testing.tearDown`` have been undeprecated. They are now the canonical setup and teardown APIs for test configuration, replacing "direct" creation of a Configurator. This is a change designed to provide a facade that will protect against any future Configurator deprecations. Paster Templates ---------------- - All paster templates now use ``pyramid.testing.setUp`` and ``pyramid.testing.tearDown`` rather than creating a Configurator "by hand" within their ``tests.py`` module, as per decision in features above. Documentation ------------- - The wiki and wiki2 tutorials now use ``pyramid.testing.setUp`` and ``pyramid.testing.tearDown`` rather than creating a Configurator "by hand", as per decision in features above. - The "Testing" narrative chapter now explains ``pyramid.testing.setUp`` and ``pyramid.testing.tearDown`` instead of Configurator creation and ``Configurator.begin()`` and ``Configurator.end()``.
-rw-r--r--CHANGES.txt27
-rw-r--r--TODO.txt11
-rw-r--r--docs/narr/MyProject/myproject/tests.py6
-rw-r--r--docs/narr/project.rst6
-rw-r--r--docs/narr/testing.rst101
-rw-r--r--docs/tutorials/wiki/src/basiclayout/tutorial/tests.py6
-rw-r--r--docs/tutorials/wiki/src/models/tutorial/tests.py6
-rw-r--r--docs/tutorials/wiki2/src/authorization/tutorial/tests.py22
-rw-r--r--docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py6
-rw-r--r--docs/tutorials/wiki2/src/models/tutorial/tests.py6
-rw-r--r--docs/tutorials/wiki2/src/views/tutorial/tests.py20
-rw-r--r--pyramid/paster_templates/pylons_basic/+package+/tests.py_tmpl7
-rw-r--r--pyramid/paster_templates/pylons_minimal/+package+/tests.py_tmpl7
-rw-r--r--pyramid/paster_templates/pylons_sqla/+package+/tests.py_tmpl8
-rw-r--r--pyramid/paster_templates/routesalchemy/+package+/tests.py_tmpl5
-rw-r--r--pyramid/paster_templates/starter/+package+/tests.py_tmpl6
-rw-r--r--pyramid/paster_templates/starter_zcml/+package+/tests.py_tmpl6
-rw-r--r--pyramid/paster_templates/zodb/+package+/tests.py_tmpl6
-rw-r--r--pyramid/testing.py21
19 files changed, 127 insertions, 156 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index c06961428..48d01c28b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,7 +1,32 @@
Next release
============
-- ...
+Features
+--------
+
+- ``pyramid.testing.setUp`` and ``pyramid.testing.tearDown`` have been
+ undeprecated. They are now the canonical setup and teardown APIs for test
+ configuration, replacing "direct" creation of a Configurator. This is a
+ change designed to provide a facade that will protect against any future
+ Configurator deprecations.
+
+Paster Templates
+----------------
+
+- All paster templates now use ``pyramid.testing.setUp`` and
+ ``pyramid.testing.tearDown`` rather than creating a Configurator "by hand"
+ within their ``tests.py`` module, as per decision in features above.
+
+Documentation
+-------------
+
+- The wiki and wiki2 tutorials now use ``pyramid.testing.setUp`` and
+ ``pyramid.testing.tearDown`` rather than creating a Configurator "by hand",
+ as per decision in features above.
+
+- The "Testing" narrative chapter now explains ``pyramid.testing.setUp`` and
+ ``pyramid.testing.tearDown`` instead of Configurator creation and
+ ``Configurator.begin()`` and ``Configurator.end()``.
1.0a9 (2011-01-08)
==================
diff --git a/TODO.txt b/TODO.txt
index 5f68974b5..c8e2a327f 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -8,10 +8,9 @@ Must-Have (before 1.0)
- Consider deprecations for ``model`` and ``resource`` APIs.
-- Re-make testing.setUp() and testing.tearDown() the canonical APIs for test
- configuration.
-
-- API docs for ``pyramid.views.action``.
+- API docs for ``pyramid.views.action``. (also, @action decorator uses
+ ``name`` for the method name; consider whether this will be confused with
+ ``name`` of ``view_config`` which means something else)
- Use a commit veto when configuring repoze.tm2 in paster templates for
non-1X, 2X, or 3X responses.
@@ -29,10 +28,6 @@ Must-Have (before 1.0)
- Turn Forbidden into a 403.
-- @action decorator uses ``name`` for the method name; consider whether this
- will be confused with ``name`` of ``view_config`` which means something
- else.
-
- Consider adding a default exception view for HTTPException and attendant
``redirect`` and ``abort`` functions ala Pylons.
diff --git a/docs/narr/MyProject/myproject/tests.py b/docs/narr/MyProject/myproject/tests.py
index b14fb37af..5fa710278 100644
--- a/docs/narr/MyProject/myproject/tests.py
+++ b/docs/narr/MyProject/myproject/tests.py
@@ -1,15 +1,13 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
class ViewTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_my_view(self):
from myproject.views import my_view
diff --git a/docs/narr/project.rst b/docs/narr/project.rst
index c1017b5c1..5af8c3231 100644
--- a/docs/narr/project.rst
+++ b/docs/narr/project.rst
@@ -876,9 +876,6 @@ represent the root.
This directory contains static assets which support the ``mytemplate.pt``
template. It includes CSS and images.
-.. index::
- single: tests.py
-
``templates/mytemplate.pt``
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -892,6 +889,9 @@ Templates are accessed and used by view configurations and sometimes by view
functions themselves. See :ref:`templates_used_directly` and
:ref:`templates_used_as_renderers`.
+.. index::
+ single: tests.py
+
``tests.py``
~~~~~~~~~~~~
diff --git a/docs/narr/testing.rst b/docs/narr/testing.rst
index 007b96c2a..08c6e355b 100644
--- a/docs/narr/testing.rst
+++ b/docs/narr/testing.rst
@@ -78,38 +78,43 @@ See :ref:`threadlocals_chapter` for information about these functions and the
data structures they return.
If your code uses these ``get_current_*`` functions or calls :app:`Pyramid`
-code which uses ``get_current_*`` functions, you will need to construct a
-:term:`Configurator` and call its ``begin`` method within the ``setUp``
-method of your unit test and call the same Configurator's ``end`` method
-within the ``tearDown`` method of your unit test.
-
-We'll also instruct the Configurator we use during testing to *autocommit*.
-Normally when a Configurator is used by an application, it defers performing
-any "real work" until its ``.commit`` method is called (often implicitly by
-the :meth:`pyramid.config.Configurator.make_wsgi_app` method). Passing
-``autocommit=True`` to the Configurator constructor causes the Configurator
-to perform all actions implied by methods called on it immediately, which is
-more convenient for unit-testing purposes than needing to call
-:meth:`pyramid.config.Configurator.commit` in each test.
-
-The use of a Configurator and its ``begin`` and ``end`` methods allows you to
-supply each unit test method in a test case with an environment that has an
-isolated registry and an isolated request for the duration of a single test.
-Here's an example of using this feature:
+code which uses ``get_current_*`` functions, you will need to call
+:func:`pyramid.testing.setUp` in your test setup and you will need to call
+:func:`pyramid.testing.tearDown` in your test teardown.
+:func:`~pyramid.testing.setUp` pushes a registry onto the :term:`thread
+local` stack, which makes the ``get_current_*`` functions work. It returns a
+:term:`Configurator` object which can be used to perform extra configuration
+required by the code under test. :func:`~pyramid.testing.tearDown` pops the
+thread local stack.
+
+Normally when a Configurator is used directly with the ``main`` block of a
+Pyramid application, it defers performing any "real work" until its
+``.commit`` method is called (often implicitly by the
+:meth:`pyramid.config.Configurator.make_wsgi_app` method). The Configurator
+returned by :func:`~pyramid.testing.setUp` is however an *autocommitting*
+Configurator which performs all actions implied by methods called on it
+immediately. This is more convenient for unit-testing purposes than needing
+to call :meth:`pyramid.config.Configurator.commit` in each test after adding
+extra configuration statements.
+
+The use of the :func:`~pyramid.testing.setUp` and
+:func:`~pyramid.testing.tearDown` functions allows you to supply each unit
+test method in a test case with an environment that has an isolated registry
+and an isolated request for the duration of a single test. Here's an example
+of using this feature:
.. code-block:: python
:linenos:
import unittest
- from pyramid.config import Configurator
+ from pyramid import testing
class MyTest(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
The above will make sure that
:func:`pyramid.threadlocal.get_current_registry` will return the
@@ -118,35 +123,33 @@ instance when :func:`pyramid.threadlocal.get_current_registry` is called in a
test case method attached to ``MyTest``. Each test case method attached to
``MyTest`` will use an isolated registry.
-The :meth:`pyramid.config.Configurator.begin` method accepts various
-arguments that influence the code run during the test. See the
-:ref:`configuration_module` chapter for information about the API of a
-:term:`Configurator`, including its ``begin`` and ``end`` methods.
+The :func:`~pyramid.testing.setUp` and :func:`~pyramid.testing.tearDown`
+functions accepts various arguments that influence the environment of the
+test. See the :ref:`testing_module` chapter for information about the extra
+arguments supported by these functions.
If you also want to make :func:`pyramid.get_current_request` return something
other than ``None`` during the course of a single test, you can pass a
-:term:`request` object into the :meth:`pyramid.config.Configurator.begin`
-method of the Configurator within the ``setUp`` method of your test:
+:term:`request` object into the :func:`pyramid.testing.setUp` within the
+``setUp`` method of your test:
.. code-block:: python
:linenos:
import unittest
- from pyramid.config import Configurator
from pyramid import testing
class MyTest(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
request = testing.DummyRequest()
- self.config.begin(request=request)
+ self.config = testing.setUp(request=request)
def tearDown(self):
- self.config.end()
+ testing.tearDown()
-If you pass a :term:`request` object into the ``begin`` method of the
-configurator within your test case's ``setUp``, any test method attached to
-the ``MyTest`` test case that directly or indirectly calls
+If you pass a :term:`request` object into :func:`pyramid.testing.setUp`
+within your test case's ``setUp``, any test method attached to the ``MyTest``
+test case that directly or indirectly calls
:func:`pyramid.threadlocal.get_current_request` will receive the request you
passed into the ``begin`` method. Otherwise, during testing,
:func:`pyramid.threadlocal.get_current_request` will return ``None``. We use
@@ -162,18 +165,18 @@ they're used by frameworks. Sorry. So here's a rule of thumb: if you don't
*know* whether you're calling code that uses the
:func:`pyramid.threadlocal.get_current_registry` or
:func:`pyramid.threadlocal.get_current_request` functions, or you don't care
-about any of this, but you still want to write test code, just always create
-an autocommitting Configurator instance and call its ``begin`` method within
-the ``setUp`` of a unit test, then subsequently call its ``end`` method in
-the test's ``tearDown``. This won't really hurt anything if the application
-you're testing does not call any ``get_current*`` function.
+about any of this, but you still want to write test code, just always call
+:func:`pyramid.testing.setUp` in your test's ``setUp`` method and
+:func:`pyramid.testing.tearDown` in your tests' ``tearDown`` method. This
+won't really hurt anything if the application you're testing does not call
+any ``get_current*`` function.
.. index::
single: pyramid.testing
single: Configurator testing API
Using the ``Configurator`` and ``pyramid.testing`` APIs in Unit Tests
-------------------------------------------------------------------------
+---------------------------------------------------------------------
The ``Configurator`` API and the ``pyramid.testing`` module provide a number
of functions which can be used during unit testing. These functions make
@@ -217,16 +220,14 @@ without needing to invoke the actual application configuration implied by its
:linenos:
import unittest
- from pyramid.config import Configurator
from pyramid import testing
class MyTest(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_view_fn_not_submitted(self):
from my.package import view_fn
@@ -277,8 +278,8 @@ performs a similar template registration and assertion. We assert at the end
of this that the renderer's ``say`` attribute is ``Yo``, as this is what is
expected of the view function in the branch it's testing.
-Note that the test calls the :meth:`pyramid.config.Configurator.begin` method
-in its ``setUp`` method and the ``end`` method of the same in its
+Note that the test calls the :func:`pyramid.testing.setUp` function in its
+``setUp`` method and the :func:`pyramid.testing.tearDown` function in its
``tearDown`` method. If you use any of the
:class:`pyramid.config.Configurator` APIs during testing, be sure to use this
pattern in your test case's ``setUp`` and ``tearDown``; these methods make
@@ -327,7 +328,6 @@ after accessing some values that require a fully set up environment.
import unittest
- from pyramid.config import Configurator
from pyramid import testing
class ViewIntegrationTests(unittest.TestCase):
@@ -337,13 +337,12 @@ after accessing some values that require a fully set up environment.
(including dependent registrations for pyramid itself).
"""
import myapp
- self.config = Configurator(package=myapp, autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
self.config.load_zcml('myapp:configure.zcml')
def tearDown(self):
""" Clear out the application registry """
- self.config.end()
+ testing.tearDown()
def test_my_view(self):
from myapp.views import my_view
diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py b/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py
index 0a3d507a0..1f3c3bb4d 100644
--- a/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py
+++ b/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py
@@ -1,15 +1,13 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
class ViewTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_my_view(self):
from tutorial.views import my_view
diff --git a/docs/tutorials/wiki/src/models/tutorial/tests.py b/docs/tutorials/wiki/src/models/tutorial/tests.py
index 839964538..51c97a95d 100644
--- a/docs/tutorials/wiki/src/models/tutorial/tests.py
+++ b/docs/tutorials/wiki/src/models/tutorial/tests.py
@@ -1,6 +1,5 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
class PageModelTests(unittest.TestCase):
@@ -50,11 +49,10 @@ class AppmakerTests(unittest.TestCase):
class ViewTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_my_view(self):
from tutorial.views import my_view
diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/tests.py b/docs/tutorials/wiki2/src/authorization/tutorial/tests.py
index 1020a8b99..08916f43c 100644
--- a/docs/tutorials/wiki2/src/authorization/tutorial/tests.py
+++ b/docs/tutorials/wiki2/src/authorization/tutorial/tests.py
@@ -1,6 +1,5 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
def _initTestingDB():
@@ -20,11 +19,10 @@ def _registerRoutes(config):
class ViewWikiTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_it(self):
from tutorial.views import view_wiki
@@ -36,12 +34,10 @@ class ViewWikiTests(unittest.TestCase):
class ViewPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.session.remove()
- self.config.end()
+ testing.tearDown()
def _callFUT(self, request):
from tutorial.views import view_page
@@ -71,12 +67,11 @@ class ViewPageTests(unittest.TestCase):
class AddPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
self.session.remove()
- self.config.end()
+ testing.tearDown()
def _callFUT(self, request):
from tutorial.views import add_page
@@ -104,12 +99,11 @@ class AddPageTests(unittest.TestCase):
class EditPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
self.session.remove()
- self.config.end()
+ testing.tearDown()
def _callFUT(self, request):
from tutorial.views import edit_page
diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py
index fa3788340..5efa6affa 100644
--- a/docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py
+++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py
@@ -1,5 +1,4 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
def _initTestingDB():
@@ -10,12 +9,11 @@ def _initTestingDB():
class TestMyView(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
_initTestingDB()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_it(self):
from tutorial.views import my_view
diff --git a/docs/tutorials/wiki2/src/models/tutorial/tests.py b/docs/tutorials/wiki2/src/models/tutorial/tests.py
index 42b0aaada..71f5e21e3 100644
--- a/docs/tutorials/wiki2/src/models/tutorial/tests.py
+++ b/docs/tutorials/wiki2/src/models/tutorial/tests.py
@@ -1,5 +1,4 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
def _initTestingDB():
@@ -9,12 +8,11 @@ def _initTestingDB():
class TestMyView(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
_initTestingDB()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_it(self):
from tutorial.views import my_view
diff --git a/docs/tutorials/wiki2/src/views/tutorial/tests.py b/docs/tutorials/wiki2/src/views/tutorial/tests.py
index 7b770f927..b9797df67 100644
--- a/docs/tutorials/wiki2/src/views/tutorial/tests.py
+++ b/docs/tutorials/wiki2/src/views/tutorial/tests.py
@@ -1,6 +1,5 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
def _initTestingDB():
@@ -20,11 +19,10 @@ def _registerRoutes(config):
class ViewWikiTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_it(self):
from tutorial.views import view_wiki
@@ -36,12 +34,11 @@ class ViewWikiTests(unittest.TestCase):
class ViewPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
self.session.remove()
- self.config.end()
+ testing.tearDown()
def _callFUT(self, request):
from tutorial.views import view_page
@@ -71,12 +68,12 @@ class ViewPageTests(unittest.TestCase):
class AddPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
- self.config = Configurator(autocommit=True)
+ self.config = testing.setUp()
self.config.begin()
def tearDown(self):
self.session.remove()
- self.config.end()
+ testing.tearDown()
def _callFUT(self, request):
from tutorial.views import add_page
@@ -104,12 +101,11 @@ class AddPageTests(unittest.TestCase):
class EditPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
self.session.remove()
- self.config.end()
+ testing.tearDown()
def _callFUT(self, request):
from tutorial.views import edit_page
diff --git a/pyramid/paster_templates/pylons_basic/+package+/tests.py_tmpl b/pyramid/paster_templates/pylons_basic/+package+/tests.py_tmpl
index 9716146e0..7fd0404f0 100644
--- a/pyramid/paster_templates/pylons_basic/+package+/tests.py_tmpl
+++ b/pyramid/paster_templates/pylons_basic/+package+/tests.py_tmpl
@@ -1,14 +1,13 @@
import unittest
-from pyramid.config import Configurator
+from pyramid import testing
class HelloHandlerTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def _makeOne(self, request):
from {{package}}.handlers.hello import HelloHandler
diff --git a/pyramid/paster_templates/pylons_minimal/+package+/tests.py_tmpl b/pyramid/paster_templates/pylons_minimal/+package+/tests.py_tmpl
index 5f6c0da65..d29d32772 100644
--- a/pyramid/paster_templates/pylons_minimal/+package+/tests.py_tmpl
+++ b/pyramid/paster_templates/pylons_minimal/+package+/tests.py_tmpl
@@ -1,14 +1,13 @@
import unittest
-from pyramid.config import Configurator
+from pyramid import testing
class MyControllerTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def _makeOne(self, request):
from {{package}}.handlers import MyHandler
diff --git a/pyramid/paster_templates/pylons_sqla/+package+/tests.py_tmpl b/pyramid/paster_templates/pylons_sqla/+package+/tests.py_tmpl
index f2f95da60..2cf485cc2 100644
--- a/pyramid/paster_templates/pylons_sqla/+package+/tests.py_tmpl
+++ b/pyramid/paster_templates/pylons_sqla/+package+/tests.py_tmpl
@@ -1,16 +1,16 @@
import unittest
+from pyramid import testing
+
class MyHandlerTests(unittest.TestCase):
def setUp(self):
- from pyramid.config import Configurator
from sqlalchemy import create_engine
from {{package}}.models import initialize_sql
self.session = initialize_sql(create_engine('sqlite://'))
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def _makeOne(self, request):
from {{package}}.handlers import MyHandler
diff --git a/pyramid/paster_templates/routesalchemy/+package+/tests.py_tmpl b/pyramid/paster_templates/routesalchemy/+package+/tests.py_tmpl
index 74ab8e08a..29aea7258 100644
--- a/pyramid/paster_templates/routesalchemy/+package+/tests.py_tmpl
+++ b/pyramid/paster_templates/routesalchemy/+package+/tests.py_tmpl
@@ -10,12 +10,11 @@ def _initTestingDB():
class TestMyView(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
_initTestingDB()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_it(self):
from {{package}}.views import my_view
diff --git a/pyramid/paster_templates/starter/+package+/tests.py_tmpl b/pyramid/paster_templates/starter/+package+/tests.py_tmpl
index e1b795b7c..33f8c50b4 100644
--- a/pyramid/paster_templates/starter/+package+/tests.py_tmpl
+++ b/pyramid/paster_templates/starter/+package+/tests.py_tmpl
@@ -1,15 +1,13 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
class ViewTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_my_view(self):
from {{package}}.views import my_view
diff --git a/pyramid/paster_templates/starter_zcml/+package+/tests.py_tmpl b/pyramid/paster_templates/starter_zcml/+package+/tests.py_tmpl
index e1b795b7c..33f8c50b4 100644
--- a/pyramid/paster_templates/starter_zcml/+package+/tests.py_tmpl
+++ b/pyramid/paster_templates/starter_zcml/+package+/tests.py_tmpl
@@ -1,15 +1,13 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
class ViewTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_my_view(self):
from {{package}}.views import my_view
diff --git a/pyramid/paster_templates/zodb/+package+/tests.py_tmpl b/pyramid/paster_templates/zodb/+package+/tests.py_tmpl
index 1d5c76c72..b0cbe33ad 100644
--- a/pyramid/paster_templates/zodb/+package+/tests.py_tmpl
+++ b/pyramid/paster_templates/zodb/+package+/tests.py_tmpl
@@ -1,15 +1,13 @@
import unittest
-from pyramid.config import Configurator
from pyramid import testing
class ViewTests(unittest.TestCase):
def setUp(self):
- self.config = Configurator(autocommit=True)
- self.config.begin()
+ self.config = testing.setUp()
def tearDown(self):
- self.config.end()
+ testing.tearDown()
def test_my_view(self):
from {{package}}.views import my_view
diff --git a/pyramid/testing.py b/pyramid/testing.py
index 96388b709..5df833634 100644
--- a/pyramid/testing.py
+++ b/pyramid/testing.py
@@ -668,14 +668,6 @@ def setUp(registry=None, request=None, hook_zca=True, autocommit=True):
:term:`application registry`; the same registry will be returned
by :func:`pyramid.threadlocal.get_current_registry` during the
execution of the test.
-
- .. warning:: Although this method of setting up a test registry
- will never disappear, after :app:`Pyramid` 1.0,
- using the ``begin`` and ``end`` methods of a
- ``Configurator`` are preferred to using
- ``pyramid.testing.setUp`` and
- ``pyramid.testing.tearDown``. See
- :ref:`testing_chapter` for more information.
"""
manager.clear()
if registry is None:
@@ -714,15 +706,6 @@ def tearDown(unhook_zca=True):
action of :func:`pyramid.testing.setUp` called with the
argument ``hook_zca=True``. If :mod:`zope.component` cannot be
imported, ignore the argument.
-
- .. warning:: Although this method of tearing a test setup down
- will never disappear, after :app:`Pyramid` 1.0,
- using the ``begin`` and ``end`` methods of a
- ``Configurator`` are preferred to using
- ``pyramid.testing.setUp`` and
- ``pyramid.testing.tearDown``. See
- :ref:`testing_chapter` for more information.
-
"""
if unhook_zca:
try:
@@ -747,9 +730,7 @@ def tearDown(unhook_zca=True):
def cleanUp(*arg, **kw):
""" :func:`pyramid.testing.cleanUp` is an alias for
- :func:`pyramid.testing.setUp`. Although this function is
- effectively deprecated as of :app:`Pyramid` 1.0, due to its
- extensive production usage, it will never be removed."""
+ :func:`pyramid.testing.setUp`. """
return setUp(*arg, **kw)
class DummyRendererFactory(object):