Django tests are not recognized

Asked

Viewed 108 times

1

When executing the test commands of Django, no test is recognized.

My file structure is as follows:

Eagle/
  eagle/
    __init__.py
    settings.py
    urls.py
    wsgi.py
  dashboard/
    __init__.py
    admin.py
    apps.py
    forms.py
    models.py
    tests.py
    urls.py
    views.py

The content of my test file is:

from django.urls import reverse, resolve
from django.test import TestCase
from . import views


# Create your tests here.
class UrlTest(TestCase):
    def dashboard_status_code(self):
        url = reverse('dashboard')
        response = self.client.get(url)
        self.assertEquals(response.status_code, 204)

    def dashboard_view(self):
        view = resolve('/accounts/')
        self.assertEquals(view.func, views.dashboard)

I have tried to execute the following commands to test:

python manage.py test
python manage.py test dashboard
python manage.py test dashboard/
python manage.py test dashboard.tests

they all bring me the following exit:

Creating test database for alias 'default'...
System check identified no issues (0 silenced).

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

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

If it helps, the code is all in Github (Here).

1 answer

0


The name of the methods that are tests, should start with test_

Then it would look something like:

from django.urls import reverse, resolve
from django.test import TestCase
from . import views


# Create your tests here.
class UrlTest(TestCase):
    def test_dashboard_status_code(self):
        url = reverse('dashboard')
        response = self.client.get(url)
        self.assertEquals(response.status_code, 204)

    def test_dashboard_view(self):
        view = resolve('/accounts/')
        self.assertEquals(view.func, views.dashboard)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.