diff options
| author | Steve Piercy <web@stevepiercy.com> | 2021-01-09 07:25:43 -0800 |
|---|---|---|
| committer | Steve Piercy <web@stevepiercy.com> | 2021-01-09 07:25:43 -0800 |
| commit | 84672a3c592a3d0cdcdec549dcd72c226d938694 (patch) | |
| tree | 4ceb04045eaeb85e11a8a9bec861689f75d97ebb /docs/narr/myproject/tests | |
| parent | f7dbb88135bd0b4cc15c9e1f3bafb78ce22e6547 (diff) | |
| download | pyramid-84672a3c592a3d0cdcdec549dcd72c226d938694.tar.gz pyramid-84672a3c592a3d0cdcdec549dcd72c226d938694.tar.bz2 pyramid-84672a3c592a3d0cdcdec549dcd72c226d938694.zip | |
Update files from cookiecutter and output from commands
Diffstat (limited to 'docs/narr/myproject/tests')
| -rw-r--r-- | docs/narr/myproject/tests/conftest.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/docs/narr/myproject/tests/conftest.py b/docs/narr/myproject/tests/conftest.py index 296205927..ec09cdb2d 100644 --- a/docs/narr/myproject/tests/conftest.py +++ b/docs/narr/myproject/tests/conftest.py @@ -1,7 +1,7 @@ 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 webtest @@ -41,29 +41,36 @@ def app_request(app): 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' - - yield request - env['closer']() + with prepare(registry=app.registry) as env: + request = env['request'] + request.host = 'example.com' + yield request @pytest.fixture -def dummy_request(app): +def dummy_request(): """ 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' 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 |
