diff options
| author | Éric Araujo <earaujo@caravan.coop> | 2020-01-16 16:11:18 -0500 |
|---|---|---|
| committer | Éric Araujo <earaujo@caravan.coop> | 2020-01-16 16:11:18 -0500 |
| commit | b102650f3ba20d3153ddff005d49f8c33fef8886 (patch) | |
| tree | ef36934735de9509f6d660782aedd9233382e865 /docs/narr/myproject/tests/conftest.py | |
| parent | d741e9baca9c6aa76158341aae4b4310b3745b7b (diff) | |
| parent | 9c153e1250e00faa06003c10c3a26886489e6210 (diff) | |
| download | pyramid-b102650f3ba20d3153ddff005d49f8c33fef8886.tar.gz pyramid-b102650f3ba20d3153ddff005d49f8c33fef8886.tar.bz2 pyramid-b102650f3ba20d3153ddff005d49f8c33fef8886.zip | |
merge master
Diffstat (limited to 'docs/narr/myproject/tests/conftest.py')
| -rw-r--r-- | docs/narr/myproject/tests/conftest.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/docs/narr/myproject/tests/conftest.py b/docs/narr/myproject/tests/conftest.py new file mode 100644 index 000000000..296205927 --- /dev/null +++ b/docs/narr/myproject/tests/conftest.py @@ -0,0 +1,69 @@ +import os +from pyramid.paster import get_appsettings +from pyramid.scripting import prepare +from pyramid.testing import DummyRequest +import pytest +import webtest + +from myproject 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. + + """ + env = prepare(registry=app.registry) + request = env['request'] + request.host = 'example.com' + + yield request + env['closer']() + +@pytest.fixture +def dummy_request(app): + """ + 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. + + - It does not have request extensions applied. + - Threadlocals are not properly pushed. + + """ + request = DummyRequest() + request.registry = app.registry + request.host = 'example.com' + + return request |
