Search code examples
pythondjangodjango-unittest

Django 1.8 - How do I test a specific file inside a tests folder?


This is my directory:

CMSApp/tests/test_page.py
CMSApp/tests/test_user.py
CMSApp/models.py
CMSApp/views.py

I want to test test_page.py only. I can do this:

python manage.py test CMSApp/tests

But that will test both test_page.py and test_user.py. When I try

python manage.py test CMSApp/tests/test_page

It says:

No module named CMSApp/tests/test_page

And when I try:

python manage.py test CMSApp/tests/test_page.py it says NoneType object is not iterable.


Solution

  • python manage.py test CMSApp.tests.test_page
    

    You need to have __init__.py in tests directory to make it a module.