Thanks for your answer.
I want to run the tests sequentially. The reason to set the session
registry to ThreadLocalRegistry was just to simulate the
scoped_session creation with scopefunc set to None, just as here:
https://bitbucket.org/zzzeek/sqlalchemy/src/148924821bf8c8537cf8ece740b26a61571215fb/lib/sqlalchemy/orm/scoping.py?at=rel_1_0#cl-44
I think the main problem using scoped_session with scopedfunc is that
when I add a model for testing, I'm not inside a web request, and
scopedfunc ( in my case set to
pyramid.threadlocal.get_current_request) returns None. So in the
registry of the scoped_session, there is now one session. When later
I'm inside the web request, the scoped_session's registry calls again
to scopedfunc, but now gets a new result and creates a second session
in the registry. The query doesn't return anything because the insert
was done in another session.
Not sure if this description is correct, but is what makes senses to
me after debugging and looking at SQLAlchemy code.
If it is correct, an alternative would be this patch:
monkeypatch.setattr('myapp.Session.registry.scopefunc', lambda: None)
to enforce the use of the same session. Does it make sense?
I also tried to patch myapp.Session directly, but since is a global
object I find it hacky. About the example you provided, I don't see
how it applies to my case, because my setUp is called before any
transaction.
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
>
https://groups.google.com/d/topic/sqlalchemy/zTuZExRXZHE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to