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

Make tests pass on Django==1.7 #20

Closed
rockymeza opened this issue Aug 16, 2014 · 9 comments · Fixed by #35
Closed

Make tests pass on Django==1.7 #20

rockymeza opened this issue Aug 16, 2014 · 9 comments · Fixed by #35

Comments

@rockymeza
Copy link
Contributor

The code seems to work as far as I can tell.

@gavinwahl
Copy link
Member

I get this error:

Traceback (most recent call last):
  File "./manage.py", line 13, in <module>
    from django.contrib.auth.tests import custom_user
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/contrib/auth/tests/custom_user.py", line 2, in <module>
    from django.contrib.auth.models import (
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 16, in <module>
    from django.contrib.contenttypes.models import ContentType
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 140, in <module>
    class ContentType(models.Model):
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/models/base.py", line 105, in __new__
    warnings.warn(msg, RemovedInDjango19Warning, stacklevel=2)
django.utils.deprecation.RemovedInDjango19Warning: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.

This is because our manage.py is importing models (225e89f) before django is set up. I added a django.setup() line in manage.py to see if that would do anything, and now I get this error:

Traceback (most recent call last):
  File "./manage.py", line 19, in <module>
    execute_from_command_line(sys.argv)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/test/runner.py", line 147, in run_tests
    old_config = self.setup_databases()
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/test/runner.py", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/test/runner.py", line 299, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 385, in create_test_db
    self.connection._test_serialized_contents = self.serialize_db_to_string()
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 421, in serialize_db_to_string
    serializers.serialize("json", get_objects(), indent=None, stream=out)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 128, in serialize
    s.serialize(queryset, **options)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/core/serializers/base.py", line 52, in serialize
    for obj in queryset:
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 417, in get_objects
    for obj in queryset.iterator():
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
    for row in compiler.results_iter():
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
    for rows in self.execute_sql(MULTI):
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
    cursor.execute(sql, params)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File ".virtualenvs/tmp-493b68aa9cd4c227/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: auth_customuser

@pipermerriam
Copy link

Why are those lines there in the first place?

You could potentially sidestep this by creating an app that is only installed during test runs and put that monkepatch code in the models.py file. Then it'll still run during setup.

@gavinwahl
Copy link
Member

They're needed to run the tests on django 1.6. I don't remember exactly why, maybe @rockymeza does.

@gavinwahl
Copy link
Member

It was issue #12

@rockymeza
Copy link
Contributor Author

I profoundly do not understand what happened in #12.

@rockymeza
Copy link
Contributor Author

I also get the auth_customuser error and I don't know where it's coming from. I think that maybe it's time we stop relying on the built-in tests.

@rockymeza
Copy link
Contributor Author

My stuff is in the 1.7-support branch, but I'm stuck on the same error as @gavinwahl was.

@gavinwahl
Copy link
Member

The django.contrib.auth tests have their own models, but where are the migrations? How do those models get created in django's tests? I think that part is just getting skipped when we run the tests.

@acatton
Copy link
Contributor

acatton commented Apr 24, 2015

@gavinwahl @rockymeza This models get created without migrations in Django tests à la syncdb. I spend 2 hours reading and understanding django's code. I finally found the obvious line. I committed a fix in 1.7-support: 280c5dd .

You can run the tests, but they don't pass. I'm still working on it.

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

Successfully merging a pull request may close this issue.

4 participants