You should include your route setup before, so that your registry gets 
populated.

I usually use pytest and its fixtures to have access to everything I need in 
testing, e.g. something like this:

import pytest

@pytest.fixture(scope='session')
def test_settings():
    import plaster
    test_settings = plaster.get_settings('testing.ini', 'app:main')
    return test_settings


@pytest.fixture
def test_registry():
    from pyramid import registry
    reg = registry.Registry('testing')
    return reg


@pytest.fixture
def test_request(test_registry):
    from pyramid import request
    req = request.Request({})
    req.registry = test_registry
    return req


@pytest.fixture
def test_config(test_settings, test_registry, test_request):
    from pyramid import testing
    config = testing.setUp(registry=test_registry, request=test_request, 
settings=test_settings)
    yield config
    testing.tearDown()


def test_foobar(test_config):
    test_config.include('your.feature')
    # assert something


test_settings fixture lives normally in the root conftest.py and the others 
where I need them.



cheers
Oliver

On 10.08.2018 17:26, Gerhard Schmidt wrote:
> Hi,
> 
> I'm writing a pyramid software using traversal with quite some complex
> ways of finding views and testing permissions to the view.
> 
> Everything works quite well in the running pyramid server but in
> unit-tests the views that are there aren't found.
> 
> I use the following code to get the callable of a view.
> 
> adapters = registry.adapters
> context_iface = providedBy(context)
> view_callable = adapters.lookup(
>         (IViewClassifier, request.request_iface, context_iface),
>         IView, name=request.view_name, default=None)
> 
> In the running server this code works fine, in unit-tests it returns
> None all the time.
> 
> I use a request object derived from pyramid.testing.DummyRequest.
> 
> Can anybody give me a pointer what I'm doing wrong.
> 
> Regards
>     Estartu
> 

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/fb996b60-ccd1-5845-3ce5-63ab5552de95%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to