Search code examples
djangounit-testingdjango-testsdjango-3.2

Django unit test is not finding any test


I want to run a unit test on test_models.py the contents of the file is below:

from django.test import TestCase
from django.contrib.auth import get_user_model


class ModelTest(TestCase):
    def test_create_user_with_email_successful(self):
        email = '[email protected]'
        password = '9876543210'
        user = get_user_model().objects.create_user(
            email=email,
            password=password
        )

        self.assertEqual(user.email, email)
        self.assertTrue(user.check_password(password))

after i run python manage.py test I get this:

System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

the file structure of my project is in the picture the file structure of my project


Solution

  • All right. I find the error. the folder tests.py does not contain any __init__.py file. thats why django cant locate test file. so it does not run the test.

    At last adding __init__.py on test folder solved the problem