I’m debugging a big unittest test for django & would like to use my normal debugging tools to do it:
- looking at the db in the django admin through runserver
- looking in the db manually.
Neither work, because unittest hasn’t committed the transaction it’s running the db side of the test in.
The obvious solution seems to be to just tell unittest not to use a transaction, or get it to commit somehow. Another way would be to create a custom settings file which would let runserver connect to the transaction. But the first idea seems like it should be really easy. Any ideas? I’m using MySQL & django 1.3.1
Consider using
TransactionTestCaseas the parent class of your test cases rather thanTestCase.TransactionTestCasedoesn’t use the transaction behavior ofTestCase, so you can commit at the point where you need to inspect the database state.Additionally, if your unit test is so big that you need to inspect its database state while it’s running, you’re probably doing it wrong. A unit test should test one thing and one thing only, and it should be fairly obvious what the state is at any point. See Carl Meyer’s Pycon 2012 talk on testing in Django for some excellent advice on writing good unit tests.