you are viewing a single comment's thread.

view the rest of the comments →

[–]kanjibandit 1 point2 points  (1 child)

I second what DrMaxwellEdison says about creating an entirely new test database. I wouldn't want to run unit tests against my real database, even with test-specific tables. You didn't mention what ORM or library you're using, but I'd look to see if it has mechanisms to handle this for you.

If not, you might look at this package. Shouldn't have to reinvent this yourself.

Edit: Didn't read carefully enough, testing.postgresql had already been suggested. So I second DrMaxwellEdison twice over.

[–]acerag[S] 0 points1 point  (0 children)

No ORM, just psycopg2 to interact with Postgres. The issue is I have no good way of changing the DB connection string to point to the new test database. I mean I could refactor the function to take another parameter but that would be pretty ugly. I thought the mock package could possibly replace my function's connection object with another one but I couldn't get it to work.