Problem running Unittest in PyCharm 1.5.4

Somehow i cannot run unittest (PyCharm 1.5.4).  Could you please help?

I am new to PyCharm and Python and sure that i am missing something... Could you please explain what is wrong and suggest how to fix it?

Steps to reproduce the error:

1. While in models.py: right-click --> popup menu: "Create unittest in models..." --> dialog: Create Rund/Debug Configuration: Unittests in models.py

2. Accept all defauls parameters (see attached Unittest_problem_PyCharm_1.5.4.png), click Ok

3. Make sure that the current configuration is "Unittests in models.py"

4. Shift + F10

5. Here comes the error:

C:\Python27\python.exe "C:\Program Files\JetBrains\PyCharm 1.5.4\helpers\pycharm\utrunner.py" models.py true

Testing started at 4:27 PM ...

Traceback (most recent call last):

  File "C:\Program Files\JetBrains\PyCharm 1.5.4\helpers\pycharm\utrunner.py", line 126, in <module>

    modules = [loadSource(a[0])]

  File "C:\Program Files\JetBrains\PyCharm 1.5.4\helpers\pycharm\utrunner.py", line 50, in loadSource

    module = imp.load_source(moduleName, fileName)

  File "models.py", line 9, in <module>

    from django.db import models

  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 14, in <module>

    if not settings.DATABASES:

  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 276, in __getattr__

    self._setup()

  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup

    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)

ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

Process finished with exit code 1

Thank you,

-igor



Attachment(s):
Unittest_problem_PyCharm_1.5.4.png
0
2 comments

Hi Igor,

as I understand you develop Django application.

Django running its tests in a different way than unittest do.

PyCharm should not suggest you create unittest if you develop django, this is fixed in PyCharm 2.0.

Instead you should create Django tests ( in the Run menu select Edit Configurations-> Django tests and type the path to the test you want to run (in a dotted way, see https://docs.djangoproject.com/en/dev/topics/testing/#running-tests) )

0

Thank you, Catherine, for the explanations :-)

-igor

0

Please sign in to leave a comment.