-1

I have not been able to execute the deletion of any User that is created during test while tearDown() methods are run. Error is puzzling, as it suggest no models are loaded.

have tried the following:

User.objects.filter(id__in=users_to_remove).delete()
User.objects.filter(username='testuser2').delete()

And both return the same error message.

Does anyone know what is the propper way to delete a user from the testing file?

Detail of Functional Test File: https://gist.github.com/leoreq/af090569980f06985f83

Error Message Returned: Erorr Message returned in terminal

Alasdair
  • 298,606
  • 55
  • 578
  • 516
leoreq
  • 3
  • 1
  • You should read up on the [testing docs](https://docs.djangoproject.com/en/1.9/topics/testing/). Django requires some extra setup, and provides the tools that do that for you. – knbk Dec 06 '15 at 15:50
  • @knbk thank you for the info. I actually have been skimming through the testing doc details and other django documentation, and find myself drowned by many details when i just want to delete a user for now. I thought this could be a simpler matter. – leoreq Dec 06 '15 at 16:10

1 Answers1

0

You need to call django.setup() after setting the environment variable.

# Set up django
import os
import sys
import django
project_dir = abspath(dirname(dirname(__file__)))
sys.path.insert(0, project_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'slapp.settings'
django.setup()
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Hi Alasadair, thaank you very much for the detail. Would you mind enlighting me a little. Why do I have to run a setup ??? What is actually being set up in this case? – leoreq Dec 06 '15 at 16:57
  • See the docs about ['standalone' Django usage](https://docs.djangoproject.com/en/1.9/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage). – Alasdair Dec 06 '15 at 17:32