I recently modified my Django project's settings to that it uses SQLite3 when I run tests instead of PostgreSQL so that my tests will run faster. However, once I did that, one of my negative unit tests that checks to verify that Django will throw an error if I try to create a user whose username exceeds 30 characters started failing. Up until this time, the test had always passed.
If I run the following test using PostgreSQL, an exception (specifically a DatabaseError) is raised and the test passes. However, if I use SQLite3 instead, no exception is raised and the test fails. I double-checked the SQLite3 auth_user schema and confirmed username is a varchar(30) field. Has anyone else experienced this? Thanks.
from django.test import TestCase
from django.contrib.auth.models import User
class SimpleTest(TestCase):
def test_simple(self):
exception_raised = True # Exception should be raised since username > 30 chars
try:
user = User.objects.create_user(username='testusertestusertestusertestuser')
except Exception as e:
exception_raised = False
assert not exception_raised, "Exception wasn't raised"