Running Django-Test fails with TransactionManagementError

205 views
Skip to first unread message

scha...@gmail.com

unread,
Apr 15, 2016, 10:53:46 AM4/15/16
to Django users
Hi All,
I took over some projects written with Python 2.7 / Django 1.5.1.
For unit tests the django-nose 1.2 (nose 1.3.3) is used and the project structure has its own tests directory which contains the testrunner.py.
As a development environment I use PyCharm.
As I wanted to run the unit tests I created a new run/debug configuration.
I did not add any Target. Just the Environment variable for DJANGO_SETTINGS_MODULE and a working directory.

But when I run/debug the tests, I always get a 'TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
It also say that no tests were found but the test DB was created.
Do you have any hints?

Connected to pydev debugger (build 141.1899)
/home/schaf/workspace/Solution/env/bin/python /home/schaf/Schreibtisch/pycharm-4.5.3/helpers/pydev/pydevd.py --multiproc --client 127.0.0.1 --port 60525 --file /home/schaf/Schreibtisch/pycharm-4.5.3/helpers/pycharm/django_test_manage.py test /home/schaf/workspace/Solution
Testing started at 10:24 ...
pydev
debugger: process 5727 is connecting

nosetests tests
.testUrlAnalyzer --with-coverage --cover-html --cover-html-dir=./tests/coverage --cover-erase --cover-package=UrlAnalyzer --verbosity=1
Creating test database for alias 'default'...
TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

Process finished with exit code 1
Empty test suite.


Thanks
schaf

John Griebel

unread,
Apr 15, 2016, 12:18:21 PM4/15/16
to django...@googlegroups.com
If you have methods using the @transaction.commit_manually decorator, comment those out temporarily. You should get a more helpful error message after doing so.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca1ca36f-0e7a-4da4-8f69-cc5c4b29a7c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

scha...@gmail.com

unread,
Apr 15, 2016, 1:02:33 PM4/15/16
to Django users
Hi John,
thanks, but I did already check for @transaction.commit_manually in the code, but PyCHarm serahc just finds this in the virtualenv/python2.7/site-packages/django_extensions/management/commands. So in my code there is nothing, would you recommend to comment those out, even if it is not from my code just to see whats going on?

Thanks
schaf

John Griebel

unread,
Apr 15, 2016, 1:11:40 PM4/15/16
to django...@googlegroups.com
That's what I would try.

scha...@gmail.com

unread,
Apr 15, 2016, 1:29:17 PM4/15/16
to Django users
Hi John,
I did now comment out those two files, but still get the same error.
Maybe I have a wrong configuration or so. I'm quite new in Django / Python.

Regards
schaf

John Griebel

unread,
Apr 15, 2016, 1:52:13 PM4/15/16
to django...@googlegroups.com
The next step (for me at least) would be to start removing/commenting out things from the tests file until you stop getting the error. Hopefully that will tell you what statement(s) may be causing the problem. Although I fear you may be correct in thinking this is a configuration issue.

Have you tried adding a Target? Does the app itself run without this error?

scha...@gmail.com

unread,
Apr 15, 2016, 2:08:21 PM4/15/16
to Django users
No I have not added a target. The reason is that there is a class deriving from NoseTestSuiteRunner.
This class defines the run_tests function which modifies the test_labels passed to the base 'constructor'.
If I add a Target for a single test (testclass.testMethod) then just this test method would be called, but if I start the debugger, I get the same error, before I run into the setUp or the specific test function. So I do not get to that point.
Also the 'empty test suite' confuses me. because I have tests, just not in a subdirectory of each app, but in a separate tests directory.

scha...@gmail.com

unread,
Apr 15, 2016, 2:49:39 PM4/15/16
to Django users
Hey John,
cool it runs now.
I had multiple problems:

1.) I granted ALL rights to my user on the test DB.
==> This solved the issue with the TransactionManagementError.

2.) I had to do some changes in my configuration and play around. Afterwards the tests were running. But not all green :-|

Thanks for your help
Have a nice weekend
schaf

John Griebel

unread,
Apr 15, 2016, 3:19:56 PM4/15/16
to django...@googlegroups.com
Glad to hear it, sorry I wasn't more help.

Reply all
Reply to author
Forward
0 new messages