1👍
Problem was completely different from what it looked like. In my test I wrote:
self.assertTrue(self.client.login(user='chris', password='password'),
'Unexpected login failure.')
When the keyword arg should instead be username
. I followed the red herring of missing data in the database, which is explained by transactions.
Thanks to mlavin in #django for the help.
0👍
I imagine it has something to do with the test database (as your initial instinct suggested). If you look at the relevant code from Django, it just runs loaddata
internally:
# django/test/testcases.py
if hasattr(self, 'fixtures'):
# We have to use this slightly awkward syntax due to the fact
# that we're using *args and **kwargs together.
call_command('loaddata', *self.fixtures,
**{'verbosity': 0, 'database': db})
Thus, if loaddata
works outside the test (as it apparently does), the problem must lie elsewhere. Given that it works with ./manage.py testserver
, I suspect that something in your codebase is inspecting sys.argv
for test
and modifying your database settings in such a way that the fixture is ignored. Could you grep
across your project for test
in unexpected places? I’ve got a section in settings.py
like this:
if 'test' in sys.argv:
# Switch to sqlite for tests (it's *way* faster)
DATABASE_ENGINE = 'sqlite3'