Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.11 SetUpClass error in FastFixtureTestCase: AttributeError: 'module' object has no attribute 'enter_transaction_management' #289

Open
MidhunSukumaranBB opened this issue Oct 6, 2017 · 3 comments

Comments

@MidhunSukumaranBB
Copy link

MidhunSukumaranBB commented Oct 6, 2017

I am using django 1.11 and django-nose==1.4.5. This is how my base test case class looks like:

class BaseTestCase(FastFixtureTestCase):

   @classmethod
    def setUpClass(cls):
        from django.db import transaction
        for db in cls._databases():
            transaction.enter_transaction_management(using=db)
            transaction.managed(True, using=db)

        cls._fixture_setup()

But getting SetUpClass error in FastFixtureTestCase: AttributeError: 'module' object has no attribute 'enter_transaction_management'. I have seen similar issue: #226. Is it fixed?

@jwhitlock
Copy link
Contributor

No, issue #226 is not fixed. You could try the code in PR #258, which would give us some confirmation that the fix works.

@lokeshatbigbasket
Copy link

@jwhitlock @bennylope I have gone through the code in #258 but, he is entirely removing for loop with transaction management. I am wondered how does this solves the problem. Don't we need transaction entirely for setting up FastfixtureTestCase ???

@jwhitlock jwhitlock added this to the Fix FastFixtureTestCase milestone Nov 8, 2017
@vhlongmore
Copy link

vhlongmore commented Oct 3, 2018

I have tried the code in #258 with Django 1.11.15 and it gets me past the AttributeError: 'module' object has no attribute 'enter_transaction_management' issue. However, now all tests error with:

$ python ./manage.py test my.tests.test_module  --settings=test_settings --processes 2
nosetests my.tests.test_module --cover-erase --cover-package=utils,2 --processes 2 --verbosity=1
Creating test database for alias 'default'...
EEEEEEEEEE
======================================================================
ERROR: My test's doc string
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/henrylongmore/.venv/myproject/lib/python2.7/site-packages/django/test/testcases.py", line 209, in __call__
    self._pre_setup()
  File "/Users/henrylongmore/.venv/myproject/lib/python2.7/site-packages/django_nose/testcases.py", line 123, in _pre_setup
    from django.contrib.sites.models import Site
  File "/Users/henrylongmore/.venv/myproject/lib/python2.7/site-packages/django/contrib/sites/models.py", line 84, in <module>
    class Site(models.Model):
  File "/Users/henrylongmore/.venv/myproject/lib/python2.7/site-packages/django/db/models/base.py", line 118, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

I did pip install git+https://github.com/bennylope/django-nose.git@fast-fixture-test-case to get the code. It could be I may have better results if I get the current master, then apply those fixes?

UPDATE: I tried pip install django_nose==1.4.5 then manually applying just the code changes from https://github.com/bennylope/django-nose.git@fast-fixture-test-case, and I still get the RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

UPDATE 2: In ignoring the files that weren't present in my virtualenv, I missed the update to INSTALLED_APPS. Now that my test settings file has

INSTALLED_APPS += ['django.contrib.sites', 'django_nose', 'django_extensions',]

the few classes that inherit from FastFixtureTestCase pass successfully. I'll try making some more inherit from it.

UPDATE 3: And that went quite poorly. At first it resulted in fewer errors, but more failures, from tests that were otherwise passing. Then I tried adding --with-fixture-bundling, and hundreds of tests failed and had errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants