diff options
| author | Steve Piercy <web@stevepiercy.com> | 2021-01-09 08:05:34 -0800 |
|---|---|---|
| committer | Steve Piercy <web@stevepiercy.com> | 2021-01-09 08:05:34 -0800 |
| commit | 6326c7ca69a5ee53a27f36ce7eec4784efaef345 (patch) | |
| tree | c395a2810a157c51eae3be086e5a9fe5f4ec7177 /docs/quick_tour/sessions/tests/conftest.py | |
| parent | 4d5d68db549c2ed297ba83679cf7ceb5169eaab3 (diff) | |
| download | pyramid-6326c7ca69a5ee53a27f36ce7eec4784efaef345.tar.gz pyramid-6326c7ca69a5ee53a27f36ce7eec4784efaef345.tar.bz2 pyramid-6326c7ca69a5ee53a27f36ce7eec4784efaef345.zip | |
Update logging and sessions steps in Quick Tour
Diffstat (limited to 'docs/quick_tour/sessions/tests/conftest.py')
| -rw-r--r-- | docs/quick_tour/sessions/tests/conftest.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/docs/quick_tour/sessions/tests/conftest.py b/docs/quick_tour/sessions/tests/conftest.py new file mode 100644 index 000000000..adc1e0f3f --- /dev/null +++ b/docs/quick_tour/sessions/tests/conftest.py @@ -0,0 +1,76 @@ +import os +from pyramid.paster import get_appsettings +from pyramid.scripting import prepare +from pyramid.testing import DummyRequest, testConfig +import pytest +import webtest + +from hello_world import main + + +def pytest_addoption(parser): + parser.addoption('--ini', action='store', metavar='INI_FILE') + +@pytest.fixture(scope='session') +def ini_file(request): + # potentially grab this path from a pytest option + return os.path.abspath(request.config.option.ini or 'testing.ini') + +@pytest.fixture(scope='session') +def app_settings(ini_file): + return get_appsettings(ini_file) + +@pytest.fixture(scope='session') +def app(app_settings): + return main({}, **app_settings) + +@pytest.fixture +def testapp(app): + testapp = webtest.TestApp(app, extra_environ={ + 'HTTP_HOST': 'example.com', + }) + + return testapp + +@pytest.fixture +def app_request(app): + """ + A real request. + + This request is almost identical to a real request but it has some + drawbacks in tests as it's harder to mock data and is heavier. + + """ + with prepare(registry=app.registry) as env: + request = env['request'] + request.host = 'example.com' + yield request + +@pytest.fixture +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 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.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 |
