lundi 7 décembre 2015

Django test ImportError: No module named 'taskbuster.unittests'

I have created a project according to a tutorial and when I am running the test it seems to create the test database and run the script but I get an error

ImportError: No module named 'taskbuster.module_name'

I have changed the settings in the virtualenvwrapper postactivate. Only made things worse, meaning the test didn't start at all. I have changed the path in the base.py settings file, but that also only made things worse.

├── db.sqlite3
├── functional_tests
│   ├── __init__.py
│   └── test_all_users.py
├── __init__.py
├── manage.py
├── taskbuster
│   ├── __init__.py
│   ├── settings
│   │   ├── base.py
│   │   ├── development.py
│   │   ├── __init__.py
│   │   ├── production.py
│   │   └── testing.py
│   ├── urls.py
│   ├── views.py
│   └── wsgi.py
└── unittests
    ├── admin.py
    ├── __init__.py
    ├── migrations
    │   ├── __init__.py
    │   └── __pycache__
    │       └── __init__.cpython-34.pyc
    ├── models.py
    ├── __pycache__
    │   ├── admin.cpython-34.pyc
    │   ├── __init__.cpython-34.pyc
    │   └── models.cpython-34.pyc
    ├── tests.py
    └── views.py

This is the INSTALLED_APPS content of settings/base.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'unittests',
)

testing.py

# -*- coding: utf-8 -*-
from .base import *
DEBUG = True

wsgi.py

import os    
from django.core.wsgi import get_wsgi_application    
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taskbuster.settings")    
application = get_wsgi_application()

manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taskbuster.settings")    
    from django.core.management import execute_from_command_line    
    execute_from_command_line(sys.argv)

postactivate in tb_test

#!/bin/bash
# This hook is sourced after this virtualenv is activated.
export DJANGO_SETTINGS_MODULE="taskbuster.settings.testing"
export SECRET_KEY="" (Secretkey has a value in the actual code)

predeactivate in tb_test

#!/bin/bash
# This hook is sourced before this virtualenv is deactivated.
unset DJANGO_SETTINGS_MODULE
unset SECRET_KEY

I have activated tb_test

$ workon tb_test

And then I run a python test

$python manage.py test

The tutorial is actually working with functional_tests, but since that did not work I created a Django app unittests, so that is why they are both in there.

I hope someone could help figure this out.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire