committing after fixture load or running tests without transactions

24 views
Skip to first unread message

Larry Martell

unread,
May 12, 2015, 3:08:35 PM5/12/15
to django...@googlegroups.com
I have a situation where I need to run an external python script in a
test after the tables are loaded from fixtures. This doesn't work
because django runs the tests in a transaction and the external python
script is running in its own MySQL connection from the test so it's in
its own transaction. When the external python script does something
that requires a foreign key look up in a table that was loaded from a
fixture it finds that table locked because the transaction in the test
has not been committed.

I tried changing the tx_isolation from REPEATABLE-READ (what it was
originally) to READ-COMMITTED and then READ-UNCOMMITTED with no change
in the behavior. Also tried adding a commit() to the beginning of the
test (i.e. after the fixtures are loaded), but that did not help
either. Is there some way to either get the transaction committed
after the fixture load or have the tests not run in a transaction?

This is on django 1.6, MySQL 5.5, InnoDB tables.

Mike Dewhirst

unread,
May 12, 2015, 8:20:23 PM5/12/15
to django...@googlegroups.com
On 13/05/2015 5:07 AM, Larry Martell wrote:
> I have a situation where I need to run an external python script in a
> test after the tables are loaded from fixtures. This doesn't work
> because django runs the tests in a transaction and the external python
> script is running in its own MySQL connection from the test so it's in
> its own transaction. When the external python script does something
> that requires a foreign key look up in a table that was loaded from a
> fixture it finds that table locked because the transaction in the test
> has not been committed.

Can you convert the script into a class and import it? That should let
the code run within the transaction.

Larry Martell

unread,
May 12, 2015, 8:29:47 PM5/12/15
to django...@googlegroups.com
On Tue, May 12, 2015 at 8:19 PM, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
> On 13/05/2015 5:07 AM, Larry Martell wrote:
>>
>> I have a situation where I need to run an external python script in a
>> test after the tables are loaded from fixtures. This doesn't work
>> because django runs the tests in a transaction and the external python
>> script is running in its own MySQL connection from the test so it's in
>> its own transaction. When the external python script does something
>> that requires a foreign key look up in a table that was loaded from a
>> fixture it finds that table locked because the transaction in the test
>> has not been committed.
>
>
> Can you convert the script into a class and import it? That should let the
> code run within the transaction.

Yes, that is what I ended up doing, but I'm still testing it and
trying to get it to work. The script in turn forked off another
script, so I also had to instantiate that. And now the test is more
different from the production environment then I'd like. It would have
been much easier if I could run the tests with no transaction.
Reply all
Reply to author
Forward
0 new messages