diff options
| author | Steve Piercy <web@stevepiercy.com> | 2020-12-30 07:24:59 -0800 |
|---|---|---|
| committer | Steve Piercy <web@stevepiercy.com> | 2020-12-30 07:24:59 -0800 |
| commit | 2ca12d8a7b317120f4d2f9c7b60308f281e78357 (patch) | |
| tree | 61c9b775680dd4ea93e118f15614185f6fa42e25 /docs/tutorials/wiki2/src/basiclayout | |
| parent | d1f88ec51042acb5a44106228cc4f8b7a3d772e0 (diff) | |
| parent | b24e9cf29b93c89b257497cd677ffcec3c9ad3a8 (diff) | |
| download | pyramid-2ca12d8a7b317120f4d2f9c7b60308f281e78357.tar.gz pyramid-2ca12d8a7b317120f4d2f9c7b60308f281e78357.tar.bz2 pyramid-2ca12d8a7b317120f4d2f9c7b60308f281e78357.zip | |
Merge branch 'master' of https://github.com/Pylons/pyramid
Diffstat (limited to 'docs/tutorials/wiki2/src/basiclayout')
| -rw-r--r-- | docs/tutorials/wiki2/src/basiclayout/tests/conftest.py | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/docs/tutorials/wiki2/src/basiclayout/tests/conftest.py b/docs/tutorials/wiki2/src/basiclayout/tests/conftest.py index 2db65f887..4ac4c60a8 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tests/conftest.py +++ b/docs/tutorials/wiki2/src/basiclayout/tests/conftest.py @@ -4,10 +4,9 @@ import alembic.command import os from pyramid.paster import get_appsettings from pyramid.scripting import prepare -from pyramid.testing import DummyRequest +from pyramid.testing import DummyRequest, testConfig import pytest import transaction -from webob.cookies import Cookie import webtest from tutorial import main @@ -89,37 +88,45 @@ def app_request(app, tm, dbsession): drawbacks in tests as it's harder to mock data and is heavier. """ - env = prepare(registry=app.registry) - request = env['request'] - request.host = 'example.com' + with prepare(registry=app.registry) as env: + request = env['request'] + request.host = 'example.com' - # without this, request.dbsession will be joined to the same transaction - # manager but it will be using a different sqlalchemy.orm.Session using - # a separate database transaction - request.dbsession = dbsession - request.tm = tm + # without this, request.dbsession will be joined to the same transaction + # manager but it will be using a different sqlalchemy.orm.Session using + # a separate database transaction + request.dbsession = dbsession + request.tm = tm - yield request - env['closer']() + yield request @pytest.fixture -def dummy_request(app, tm, dbsession): +def dummy_request(tm, dbsession): """ A lightweight dummy request. - This request is ultra-lightweight and should be used only when the - request itself is not a large focus in the call-stack. - - It is way easier to mock and control side-effects using this object. + This request is ultra-lightweight and should be used only when the request + itself is not a large focus in the call-stack. It is much easier to mock + and control side-effects using this object, however: - It does not have request extensions applied. - Threadlocals are not properly pushed. """ request = DummyRequest() - request.registry = app.registry request.host = 'example.com' request.dbsession = dbsession request.tm = tm return request + +@pytest.fixture +def dummy_config(dummy_request): + """ + A dummy :class:`pyramid.config.Configurator` object. This allows for + mock configuration, including configuration for ``dummy_request``, as well + as pushing the appropriate threadlocals. + + """ + with testConfig(request=dummy_request) as config: + yield config |
