Running django tutorial tests fail - No module named polls.tests

前端 未结 4 1661
清酒与你
清酒与你 2020-12-01 01:41

I\'m playing with django 1.6 tutorial but i can\'t run tests. My project (name mydjango) and app structure (name is polls) are as shown below in a virtualenv. (.nja files ar

4条回答
  •  旧巷少年郎
    2020-12-01 02:36

    I had exactly the same issue with my Django project:

    $ python manage test polls.tests
    

    worked fine whereas the following failed with an import error:

    $ python manage test polls
    $ python manage test
    (...)
    ImportError: Failed to import test module: mydjango.polls.tests
    Traceback (most recent call last):
    (...)
    ImportError: No module named polls.tests
    

    Check carefully the error message: Django's test runner tries to import the tests from mydjango.polls.tests where mydjango is the name of the root directory (the container for your project).

    I fixed this issue by deleting the __init__.py file in mydjango directory (at the same level than manage.py file). This directory is not supposed to be a python module and it seems to mess up with Django's test runner if it is the case.

    So just deleting the _init_.py file should fix our problem:

    $ rm mydjango/__init__.py
    

提交回复
热议问题