SetUp functions for multiple test cases
Diez B. Roggisch
deets at nospam.web.de
Tue Jan 20 15:56:50 CET 2009
Georg Schmid wrote:
> I've just started working with unittests and already hit a snag. I
> couldn't find out how to implement a setup function, that is executed
> only _once_ before all of the tests. Specifically, I need this for
> testing my database interface, and naturally I don't want to create a
> new database in-memory and fill it with example data for every single
> test case.
> Obviously I could simply execute that setup function separately from
> the unittesting procedure, but then there'd be no point in
> implementing all my unittests in a clean manner in the first place,
> apart from further problems arising due to how my IDE (Eric4) picks
> test cases from project files.
> Perhaps I missed something about the concept of TestSuites. Thanks in
Why don't you simply store the state of the DB being set-up somewhere
(globally for example), and only execute the db-setup-code (inside setUp of
course) depending on the value of that variable?
More information about the Python-list