I am trying to wrap my head around how to do Dependency Injection with 
SQLAlchemy and I am walking in circles.

I want to be able to mock out SA for most of my tests. I trust SA and don't 
want to test serialisation into the DB. I just want to test my own code. So 
I was thinking to do dependency injection, and mock out SA during testing.

But I don't know what to mock out, how and when to set up the session 
properly, without doing it at the module level (which causes unwanted 
side-effects only by importing the module).

The only solution which comes to mind is to have one "singleton" which 
deals with that. But that feels very unpythonic to me and I am wondering if 
there's a better solution.

I also saw that "create_engine" has an optional "module" kwarg, which I 
could mock out. But then SA begins complaining that the return types are 
not correct. And I don't want to specify return values for every possible 
db-module call. That's way out of scope of my tests. I am not calling 
anything on the db-module. That's SA's job, and, as said, I already trust 
SA.

Whenever I work on this I always run into the session_maker initialisation 
as well. The examples to this on the module level, which I really make me 
feel uneasy.

Any tips? Just prodding myself in the right direction might help me out 
enough.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to