dimanche 8 février 2015

Running unit tests from Django libraries without manage.py

I'm trying to write unit tests for a Python library that depends on Django. They work fine when I try to run them as part of a Django project:



>python manage.py test mexaminer.tests
Creating test database for alias 'default'...
.
----------------------------------------------------------------------
Ran 1 test in 0.006s

OK
Destroying test database for alias 'default'...


When I try to run them on their own, this happens:



>python -m unittest mexaminer.tests
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 38, in _set
up
settings_module = os.environ[ENVIRONMENT_VARIABLE]
File "C:\Python34\lib\os.py", line 631, in __getitem__
raise KeyError(key) from None
KeyError: 'DJANGO_SETTINGS_MODULE'


The same thing happens when I run python -m django.utils.unittest mexaminer.tests. Is there a way to run my unit tests without setting up a full Django project? Source code is here.


Aucun commentaire:

Enregistrer un commentaire