Flakey tests and django.db.utils.InterfaceError: connection already closed

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Flakey tests and django.db.utils.InterfaceError: connection already closed

thinkwelldesigns
I could use some assistance in troubleshooting a psycopg2.InterfaceError problem that has erratic behavior. Here is the test module suite that I'm running to test these models, and in this state all the tests in the module pass. However, it's extremely easy to trigger a psycopg2.InterfaceError, although not relating to the lines changed. For example, if I change:

class TestSilly(SimpleTestCase):
 
   
def test_is_not_false(self):
       
self.assertTrue(False is not True)


to

class TestSilly(TestCase):
 
   
def test_is_not_false(self):
       
self.assertTrue(False is not True)

 

Then this error is raised, but referencing TestPolicyModel instead of TestSilly!

======================================================================
ERROR
: test_toggle_autofix (accounts.tests.test_models.TestPolicyModel)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
psycopg2
.InterfaceError: connection already closed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 
File "apps/accounts/tests/test_models.py", line 174, in test_toggle_autofix
    p
= Policy.objects.first()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
   
return getattr(self.get_queryset(), name)(*args, **kwargs)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 490, in first
    objects
= list((self if self.ordered else self.order_by('pk'))[:1])
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 162, in __iter__
   
self._fetch_all()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 965, in _fetch_all
   
self._result_cache = list(self.iterator())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 238, in iterator
    results
= compiler.execute_sql()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py", line 838, in execute_sql
    cursor
= self.connection.cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 164, in cursor
    cursor
= self.make_cursor(self._cursor())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 97, in __exit__
    six
.reraise(dj_exc_type, dj_exc_value, traceback)
 
File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 658, in reraise
   
raise value.with_traceback(tb)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
django
.db.utils.InterfaceError: connection already closed


For another example, if I change

TestPolicyModel(TestCase)


to

TestPolicyModel(SimpleTestCase)


then, I get the following error regarding TestRedwoodModel

======================================================================
ERROR
: setUpClass (accounts.tests.test_models.TestRedwoodModel)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
psycopg2
.InterfaceError: connection already closed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 
File "apps/accounts/tests/test_models.py", line 195, in setUpClass
    cls
.ru = RedwoodUsers.objects.first()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
   
return getattr(self.get_queryset(), name)(*args, **kwargs)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 490, in first
    objects
= list((self if self.ordered else self.order_by('pk'))[:1])
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 162, in __iter__
   
self._fetch_all()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 965, in _fetch_all
   
self._result_cache = list(self.iterator())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 238, in iterator
    results
= compiler.execute_sql()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py", line 838, in execute_sql
    cursor
= self.connection.cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 164, in cursor
    cursor
= self.make_cursor(self._cursor())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 97, in __exit__
    six
.reraise(dj_exc_type, dj_exc_value, traceback)
 
File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 658, in reraise
   
raise value.with_traceback(tb)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
django
.db.utils.InterfaceError: connection already closed



If I comment out TestRedwoodModel, then TestPolicyModel passes, whether it inherits SimpleTestCase or TestCase.

So I'm thoroughly confused, and can't seem to discern a pattern in these tracebacks. Any assistance is greatly appreciated!

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54a5147c-5ec7-4a58-b188-d68fd8c81716%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Flakey tests and django.db.utils.InterfaceError: connection already closed

Christopher R.
Have you been able to fix the problem? I am encountering the same issue on both Django 1.8.4 and 1.8.5.

Any help would be appreciated.

On Thursday, October 8, 2015 at 3:38:16 PM UTC+1, thinkwell wrote:
I could use some assistance in troubleshooting a psycopg2.InterfaceError problem that has erratic behavior. Here is <a href="http://pastebin.com/QrD6aQGK" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FQrD6aQGK\46sa\75D\46sntz\0751\46usg\75AFQjCNF3Qv-QOgOGsQGhxVkn1FYJthJLAQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FQrD6aQGK\46sa\75D\46sntz\0751\46usg\75AFQjCNF3Qv-QOgOGsQGhxVkn1FYJthJLAQ&#39;;return true;">the test module suite that I'm running to test <a href="http://pastebin.com/FWCWg9Q5" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FFWCWg9Q5\46sa\75D\46sntz\0751\46usg\75AFQjCNElUSEGP2uYNg78iaxqV6d8dQikSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FFWCWg9Q5\46sa\75D\46sntz\0751\46usg\75AFQjCNElUSEGP2uYNg78iaxqV6d8dQikSQ&#39;;return true;">these models, and in this state all the tests in the module pass. However, it's extremely easy to trigger a psycopg2.InterfaceError, although not relating to the lines changed. For example, if I change:

class TestSilly(SimpleTestCase):
 
   
def test_is_not_false(self):
       
self.assertTrue(False is not True)


to

class TestSilly(TestCase):
 
   
def test_is_not_false(self):
       
self.assertTrue(False is not True)

 

Then this error is raised, but referencing TestPolicyModel instead of TestSilly!

======================================================================
ERROR
: test_toggle_autofix (accounts.tests.test_models.TestPolicyModel)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
psycopg2
.InterfaceError: connection already closed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 
File "apps/accounts/tests/test_models.py", line 174, in test_toggle_autofix
    p
= Policy.objects.first()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
   
return getattr(self.get_queryset(), name)(*args, **kwargs)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 490, in first
    objects
= list((self if self.ordered else self.order_by('pk'))[:1])
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 162, in __iter__
   
self._fetch_all()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 965, in _fetch_all
   
self._result_cache = list(self.iterator())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 238, in iterator
    results
= compiler.execute_sql()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py", line 838, in execute_sql
    cursor
= self.connection.cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 164, in cursor
    cursor
= self.make_cursor(self._cursor())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 97, in __exit__
    six
.reraise(dj_exc_type, dj_exc_value, traceback)
 
File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 658, in reraise
   
raise value.with_traceback(tb)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
django
.db.utils.InterfaceError: connection already closed


For another example, if I change

TestPolicyModel(TestCase)


to

TestPolicyModel(SimpleTestCase)


then, I get the following error regarding TestRedwoodModel

======================================================================
ERROR
: setUpClass (accounts.tests.test_models.TestRedwoodModel)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
psycopg2
.InterfaceError: connection already closed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 
File "apps/accounts/tests/test_models.py", line 195, in setUpClass
    cls
.ru = RedwoodUsers.objects.first()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
   
return getattr(self.get_queryset(), name)(*args, **kwargs)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 490, in first
    objects
= list((self if self.ordered else self.order_by(
...

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/716aa277-232d-40e0-ab6f-e2015158ab32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Flakey tests and django.db.utils.InterfaceError: connection already closed

Tim Graham-2
A test project that reproduces the problem would be helpful.

On Tuesday, October 27, 2015 at 9:14:13 AM UTC-4, Christopher R. wrote:
Have you been able to fix the problem? I am encountering the same issue on both Django 1.8.4 and 1.8.5.

Any help would be appreciated.

On Thursday, October 8, 2015 at 3:38:16 PM UTC+1, thinkwell wrote:
I could use some assistance in troubleshooting a psycopg2.InterfaceError problem that has erratic behavior. Here is <a href="http://pastebin.com/QrD6aQGK" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FQrD6aQGK\46sa\75D\46sntz\0751\46usg\75AFQjCNF3Qv-QOgOGsQGhxVkn1FYJthJLAQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FQrD6aQGK\46sa\75D\46sntz\0751\46usg\75AFQjCNF3Qv-QOgOGsQGhxVkn1FYJthJLAQ&#39;;return true;">the test module suite that I'm running to test <a href="http://pastebin.com/FWCWg9Q5" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FFWCWg9Q5\46sa\75D\46sntz\0751\46usg\75AFQjCNElUSEGP2uYNg78iaxqV6d8dQikSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FFWCWg9Q5\46sa\75D\46sntz\0751\46usg\75AFQjCNElUSEGP2uYNg78iaxqV6d8dQikSQ&#39;;return true;">these models, and in this state all the tests in the module pass. However, it's extremely easy to trigger a psycopg2.InterfaceError, although not relating to the lines changed. For example, if I change:

class TestSilly(SimpleTestCase):
 
   
def test_is_not_false(self):
       
self.assertTrue(False is not True)


to

class TestSilly(TestCase):
 
   
def test_is_not_false(self):
       
self.assertTrue(False is not True)

 

Then this error is raised, but referencing TestPolicyModel instead of TestSilly!

======================================================================
ERROR
: test_toggle_autofix (accounts.tests.test_models.TestPolicyModel)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
psycopg2
.InterfaceError: connection already closed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 
File "apps/accounts/tests/test_models.py", line 174, in test_toggle_autofix
    p
= Policy.objects.first()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
   
return getattr(self.get_queryset(), name)(*args, **kwargs)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 490, in first
    objects
= list((self if self.ordered else self.order_by('pk'))[:1])
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 162, in __iter__
   
self._fetch_all()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 965, in _fetch_all
   
self._result_cache = list(self.iterator())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 238, in iterator
    results
= compiler.execute_sql()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py", line 838, in execute_sql
    cursor
= self.connection.cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 164, in cursor
    cursor
= self.make_cursor(self._cursor())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 97, in __exit__
    six
.reraise(dj_exc_type, dj_exc_value, traceback)
 
File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 658, in reraise
   
raise value.with_traceback(tb)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
django
.db.utils.InterfaceError: connection already closed


For another example, if I change

TestPolicyModel(TestCase)


to

TestPolicyModel(SimpleTestCase)


then, I get the following error regarding TestRedwoodModel

======================================================================
ERROR
: setUpClass (accounts.tests.test_models.TestRedwoodModel)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
psycopg2
.InterfaceError: connection already closed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 
File "apps/accounts/tests/test_models.py", line 195, in setUpClass
    cls
.ru = RedwoodUsers.objects.first()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
   
return getattr(self.get_queryset(), name)(*args, **kwargs)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 490, in first
    objects
= list((self if self.ordered else self.order_by(
...

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f3075d88-f670-4dca-b413-5b4d6a20d78c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Flakey tests and django.db.utils.InterfaceError: connection already closed

Collin Anderson-2
In reply to this post by Christopher R.
Hello,

Here are some questions that might help debugging this:

Do other tests that use the database run ok?

If you run _only_ this test, is it still a problem?

Are you using threads at all?

Is there an exception that's being silenced somewhere else?

Collin


On Tuesday, October 27, 2015 at 9:14:13 AM UTC-4, Christopher R. wrote:
Have you been able to fix the problem? I am encountering the same issue on both Django 1.8.4 and 1.8.5.

Any help would be appreciated.

On Thursday, October 8, 2015 at 3:38:16 PM UTC+1, thinkwell wrote:
I could use some assistance in troubleshooting a psycopg2.InterfaceError problem that has erratic behavior. Here is <a href="http://pastebin.com/QrD6aQGK" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FQrD6aQGK\46sa\75D\46sntz\0751\46usg\75AFQjCNF3Qv-QOgOGsQGhxVkn1FYJthJLAQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FQrD6aQGK\46sa\75D\46sntz\0751\46usg\75AFQjCNF3Qv-QOgOGsQGhxVkn1FYJthJLAQ&#39;;return true;">the test module suite that I'm running to test <a href="http://pastebin.com/FWCWg9Q5" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FFWCWg9Q5\46sa\75D\46sntz\0751\46usg\75AFQjCNElUSEGP2uYNg78iaxqV6d8dQikSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fpastebin.com%2FFWCWg9Q5\46sa\75D\46sntz\0751\46usg\75AFQjCNElUSEGP2uYNg78iaxqV6d8dQikSQ&#39;;return true;">these models, and in this state all the tests in the module pass. However, it's extremely easy to trigger a psycopg2.InterfaceError, although not relating to the lines changed. For example, if I change:

class TestSilly(SimpleTestCase):
 
   
def test_is_not_false(self):
       
self.assertTrue(False is not True)


to

class TestSilly(TestCase):
 
   
def test_is_not_false(self):
       
self.assertTrue(False is not True)

 

Then this error is raised, but referencing TestPolicyModel instead of TestSilly!

======================================================================
ERROR
: test_toggle_autofix (accounts.tests.test_models.TestPolicyModel)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
psycopg2
.InterfaceError: connection already closed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 
File "apps/accounts/tests/test_models.py", line 174, in test_toggle_autofix
    p
= Policy.objects.first()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
   
return getattr(self.get_queryset(), name)(*args, **kwargs)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 490, in first
    objects
= list((self if self.ordered else self.order_by('pk'))[:1])
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 162, in __iter__
   
self._fetch_all()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 965, in _fetch_all
   
self._result_cache = list(self.iterator())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 238, in iterator
    results
= compiler.execute_sql()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py", line 838, in execute_sql
    cursor
= self.connection.cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 164, in cursor
    cursor
= self.make_cursor(self._cursor())
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 97, in __exit__
    six
.reraise(dj_exc_type, dj_exc_value, traceback)
 
File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 658, in reraise
   
raise value.with_traceback(tb)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
django
.db.utils.InterfaceError: connection already closed


For another example, if I change

TestPolicyModel(TestCase)


to

TestPolicyModel(SimpleTestCase)


then, I get the following error regarding TestRedwoodModel

======================================================================
ERROR
: setUpClass (accounts.tests.test_models.TestRedwoodModel)
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 137, in _cursor
   
return self.create_cursor()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 212, in create_cursor
    cursor
= self.connection.cursor()
psycopg2
.InterfaceError: connection already closed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 
File "apps/accounts/tests/test_models.py", line 195, in setUpClass
    cls
.ru = RedwoodUsers.objects.first()
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
   
return getattr(self.get_queryset(), name)(*args, **kwargs)
 
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py", line 490, in first
    objects
= list((self if self.ordered else self.order_by(
...

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7a9b3fd6-a3b0-4066-bc52-3cd2b38fb947%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Flakey tests and django.db.utils.InterfaceError: connection already closed

thinkwelldesigns
I'd parked this problem for quite some time, until it finally became incontestably necessary to wrestle the issue to the ground.

What I found, after many hours of experimenting - too much like the random walk, I suppose, is that every time I overrode setUpClass, I also had to override tearDownClass. Before, if I had nothing to clean up after the test, I wouldn't bother overriding tearDownClass.

When I went to all my tests and added

@classmethod
def tearDownClass(cls):
     
pass

Then my problems went away. I reckon that's in the docs somewhere. But it seems to me that tearDownClass should be able to degrade more gracefully. :weary:



--
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 [hidden email].
To post to this group, send email to [hidden email].
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/48645d77-8c7d-46aa-82fc-24ea98153190%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Flakey tests and django.db.utils.InterfaceError: connection already closed

Peter Nociar
Thanks, this fixed my issue. 

On Tuesday, 12 April 2016 04:28:21 UTC+1, thinkwell wrote:
I'd parked this problem for quite some time, until it finally became incontestably necessary to wrestle the issue to the ground.

What I found, after many hours of experimenting - too much like the random walk, I suppose, is that every time I overrode setUpClass, I also had to override tearDownClass. Before, if I had nothing to clean up after the test, I wouldn't bother overriding tearDownClass.

When I went to all my tests and added

@classmethod
def tearDownClass(cls):
     
pass

Then my problems went away. I reckon that's in the docs somewhere. But it seems to me that tearDownClass should be able to degrade more gracefully. :weary:



--
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 [hidden email].
To post to this group, send email to [hidden email].
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/10b1b43c-8f7c-4f31-ac83-919c85673c3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.