Unittests and external data....

mcherm at mcherm.com mcherm at mcherm.com
Thu Mar 20 13:55:26 CET 2003

Michael Chermside writes:
> I don't particularly like having the factory functions behave
> differently under unittesting, but that's the best solution
> I've come up with.

Steven Taschuk replies:
> Why not just pass in the factory function as a parameter to the
> code that needs it (with a default value, naturally)?  The testing
> code can then just pass in its own mock version.

Good question. I usually wind up having things like the the core
factory for accessing an external service as system globals
(whatever that means in the language I'm using). So, for instance,
I don't have to pass around a SQLFactory object to every function
that might call a function that might need to access the database.
It becomes even more extreme if you consider the ConfigFileAccess
object... would I pass that to every function everywhere just in
order to allow arbitrary code to allow configuration? Of course,
the downside of using global data is, as always, that you can't
change it for one bit of code (like the unit tests) whenever you
want without affecting everything else.

-- Michael Chermside

More information about the Python-list mailing list