I mock as much as feasible, so I have fake DB Session and Query
classes with a list of fake results to return in order. When I want a
real database connection, I have PyTest fixtures that read the INI
path from a command-line option (pytest_addoption(),
pyramid.paster.getappsettings()), and resolve it to a SQLAlchemy
Session that always rolls back (PyTest request.addfinalizer()). That's
a PyTest's request, not a Pyramid request.
The only time I have to do more is when testing views that call
Pyramid 'request.route_path()'. For those I use something like this:
"""
settings = {...}
with pyramid.testing.testConfig(settings=settings) as config:
config.add_route(...)
request = pyramid.testing.DummyRequest(registry=config.registry)
request.sa_session_main = ... # Emulate property in my real
request subclass. (SQLAlchemy session.)
a = the_view(request)
assert a["my_url"] = expected_url
"""
If necessary I'll use a real Pyramid Request.blank() or my real
Request subclass, but this is sufficient for a lot of cases.