Database + testing [solved]


#1

Howdy, gentle people.

I am looking for a way to write some tests around my db access methods.

So I need my fixtures to run the create_tables command in setup and possibly the drop_tables on cleanup.

How should I go about doing this, or am I going about this in the wrong way?

Thanks.


#2

Hello,
that might bot be the good place to post it.
Anyway I did a pytest plugin for ponyorm sa I can tell you some things you have to think about :

  • how to configure test database ?
  • how to manage transaction in your tests ?
  • create the database is easy but reset the db after each test is harder because, that make your tests very slow if you do a drop/recareate table each time(except if you run it in memory. In my plugin, I create the database once and then I deleted all the data for all tables , which is much faster. The side effect is that you also have to take care of the SQL sequences (auto fields …)

Depending your ORM it might already be something ok for your usage.

here is the code if you want to look at https://github.com/jgirardet/pytest-ponyorm


#3

I apologize if I posted to the wrong forum.

Might I humbly inquire what is the recommended forum for such questions?


#4

[solved] Dan Cardin’s Apistar example has what I was looking for.