# I am unable to run my unit tests

**URL:** <https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774>\
**Category:** Mystery Errors\
**Created:** [July 13, 2022, 3:56pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774 "2022-07-13T15:56:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [July 13, 2022, 3:56pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/1 "2022-07-13T15:56:55Z")

</div>

Hi there,

Whenever I run my unit tests, I use this command `python manage.py test`, but my tests are not running, I get the following message:

```auto
Found 0 test(s).
System check identified no issues (0 silenced).

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

OK

```

**NOTE:** I am using MySQL Database instead of the default SQLite. Does this have to do anything with the unit tests anyway?

I have following hierarchy of my project files and folders:

```auto
--[PROJECT-NAME]
------apps
----------[APP-NAME]
--------------migrations
--------------templates
--------------models.py
--------------test.py
--------------urls.py
--------------views.py
------[PROJECT-NAME]
----------settings.py
----------urls.py
------manage.py

```

And this is my `tests.py` file

```auto
from django.test import TestCase
from apps.accounts.models import User, Invitation

class TestModels(TestCase):    
    def test_sending_password_reset_email(self):
        user = User.objects.create(
            login = "testuser@test.com",
            email = "testuser@test.com",
            password = "TestPassword1!"
        )

        email_sent = user.send_password_reset_email()

        self.assertTrue(email_sent)

    def test_accepting_invitation(self):
        user = User.objects.create(
            login = "testuser@test.com",
            email = "testuser@test.com",
            password = "TestPassword1!"
        )

        invitation = Invitation.objects.create(created_by = user)

        accepted = invitation.accept(user, "testinguser@test.com", "TestingPassword1!")

        self.assertTrue(accepted)

    def test_cancelling_invitation(self):
        user = User.objects.create(
            login = "testuser@test.com",
            email = "testuser@test.com",
            password = "TestPassword1!"
        )

        invitation = Invitation.objects.create(created_by = user)

        invitation.cancel()

        self.assertTrue(invitation.is_canceled)

    def test_sending_invite_user_email(self):
        user = User.objects.create(
            login = "testuser@test.com",
            email = "testuser@test.com",
            password = "TestPassword1!"
        )

        invitation = Invitation.objects.create(created_by = user)

        message = invitation.send_invite_user_email()

        self.assertEqual(message, "Success")

```

and these are the function signatures in my `models.py`:

```auto
def send_password_reset_email(self) -> bool:
    .
    .
    .

def accept(
        self,
        user: User,
        login: str,
        password: str
) -> bool:
    .
    .
    .

def cancel(self):
    .
    .
    .

def send_invite_user_email(self) -> str:
    .
    .
    .

```

Anyone knows what wrong I am doing? Why my unit tests are not running?

---

<div class="post-metadata">

**Author:** ![Rigo-Villalta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rigo-villalta/32/5667_2.png) [@Rigo-Villalta](https://forum.djangoproject.com/u/Rigo-Villalta)\
**Post date:** [July 13, 2022, 5:19pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/2 "2022-07-13T17:19:39Z")

</div>

Hello @khaw235

Are you able to run? :

```auto
python manage.py runserver

```

without complains?

---

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [July 13, 2022, 6:12pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/3 "2022-07-13T18:12:47Z")

</div>

@Rigo-Villalta yes, I am able to run the server, but I get the following warning though:

```auto
WARNINGS:
?: (staticfiles.W004) The directory 'D:\Projects\meistery\projects\pricing_password_management_poc\inviteandresetpass\static' in the STATICFILES_DIRS setting does not exist.

```

---

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [July 13, 2022, 6:27pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/4 "2022-07-13T18:27:29Z")

</div>

@Rigo-Villalta I solved this warning by creating a folder named `static` in the project directory, but I am still unable to get any test run, it shows same message `Ran 0 tests`

---

<div class="post-metadata">

**Author:** ![Rigo-Villalta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rigo-villalta/32/5667_2.png) [@Rigo-Villalta](https://forum.djangoproject.com/u/Rigo-Villalta)\
**Post date:** [July 13, 2022, 7:25pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/5 "2022-07-13T19:25:07Z")

</div>

> [@khaw235](#):
>
> `python manage.py test`

try to run the test file directly:

```auto
python manage.py test apps/app_name/test.py

```

And please post the result here.

---

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [July 13, 2022, 7:39pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/6 "2022-07-13T19:39:45Z")

</div>

@Rigo-Villalta I ran the command as you said and I got following Traceback:

```auto
python manage.py test apps/accounts/tests.py
Traceback (most recent call last):
  File "D:\Projects\meistery\projects\pricing_password_management_poc\inviteandresetpass\manage.py", line 22, in <module>
    main()
  File "D:\Projects\meistery\projects\pricing_password_management_poc\inviteandresetpass\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\core\management\ __init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\core\management\ __init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\core\management\commands\test.py", line 24, in run_from_argv super().run_from_argv(argv)
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv        
    self.execute(*args, **cmd_options)
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\core\management\base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\core\management\commands\test.py", line 68, in handle       
    failures = test_runner.run_tests(test_labels)
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\test\runner.py", line 994, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\test\runner.py", line 847, in build_suite
    tests = self.load_tests_for_label(label, discover_kwargs)
  File "D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\test\runner.py", line 809, in load_tests_for_label
    raise RuntimeError(
RuntimeError: One of the test labels is a path to a file: 'apps/accounts/tests.py', which is not supported. Use a dotted module name or path to a directory instead.

```

---

<div class="post-metadata">

**Author:** ![Rigo-Villalta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rigo-villalta/32/5667_2.png) [@Rigo-Villalta](https://forum.djangoproject.com/u/Rigo-Villalta)\
**Post date:** [July 13, 2022, 7:45pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/7 "2022-07-13T19:45:28Z")

</div>

Sorry, my mistake.

Try this:

```auto
python manage.py test apps/accounts/

```

---

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [July 13, 2022, 7:49pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/8 "2022-07-13T19:49:57Z")

</div>

> [@Rigo-Villalta](#):
>
> `python manage.py test apps/accounts/`

I got this now:

```auto
Found 4 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\db\models\fields\ __init__.py:1534: RuntimeWarning: DateTimeField Invitation.accepted_at received a naive datetime (2022-07-14 00:47:42.187885) while time zone support is active.
  warnings.warn(
..D:\Projects\meistery\venvs\inviteandresetpass\lib\site-packages\django\db\models\fields\ __init__.py:1534: RuntimeWarning: DateTimeField Invitation.expiration_date received a naive datetime (2022-07-15 00:47:42.308024) while time zone support is active.
  warnings.warn(
..
----------------------------------------------------------------------
Ran 4 tests in 1.127s

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

```

OK, its working now. So I have two questions:

- Why does not it run with `python manage.py test`? And how can I make these tests run with this command?
- Are these tests passed? I mean my functions whom I am testing are correct?

---

<div class="post-metadata">

**Author:** ![Rigo-Villalta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rigo-villalta/32/5667_2.png) [@Rigo-Villalta](https://forum.djangoproject.com/u/Rigo-Villalta)\
**Post date:** [July 13, 2022, 7:58pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/9 "2022-07-13T19:58:12Z")

</div>

> [@khaw235](#):
>
> Why does not it run with `python manage.py test`? And how can I make these tests run with this command?

I think you haven’t add “apps” to your path. [See this](https://stackoverflow.com/a/50364893/6207085)

> [@khaw235](#):
>
> Are these tests passed? I mean my functions whom I am testing are correct?

Yes they are correct, but you have a warning. I think the problem is that you are using datetime.now in your models, that is not the best practice, [read this](https://docs.djangoproject.com/en/4.0/topics/i18n/timezones/#naive-and-aware-datetime-objects).

---

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [July 14, 2022, 6:09am UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/10 "2022-07-14T06:09:49Z")

</div>

> [@Rigo-Villalta](#):
>
> I think you haven’t add “apps” to your path. [See this](https://stackoverflow.com/a/50364893/6207085)

I added ‘apps’ to the path following the method told in the link by adding `sys.path.append(str(BASE_DIR / 'apps'))`, but I still get `Ran 0 tests` on running `python manage.py test` command.

---

<div class="post-metadata">

**Author:** ![MrCordeiro](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrcordeiro/32/785_2.png) [@MrCordeiro](https://forum.djangoproject.com/u/MrCordeiro)\
**Post date:** [July 20, 2022, 5:24pm UTC](https://forum.djangoproject.com/t/i-am-unable-to-run-my-unit-tests/14774/11 "2022-07-20T17:24:25Z")

</div>

That StackOverflow answer was very old. On recent Django versions, you don’t need that to add the apps to the path yourself. If `BASE_DIR` is pointing to the right location and the app is listed in `INSTALLED_APPS`, django discovers the app automatically.

One thing to try is to rename your `test.py` file to `tests.py`.

Another idea, because you have your apps under an `apps` folder, is to ensure it’s being listed correctly.

Make sure you are using the full name on `settings.py` and `apps.py`:

```python
#settings.py

INSTALLED_APPS = [
   ...
   "apps.myapp",
   ...
]

```

```python
#app.py
from django.apps import AppConfig

class MyAppConfig(AppConfig):
    name = "apps.myapp"

```
