Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run django tests by tag

I have problem because I wanted to tag some test in django but when I type in console

from django.test import tag, TestCase


@tag('fast', 'something')
class SomeTestCase(TestCase):
    def setUp(self):
        # do something

    def test_something(self):
        # do something

when I type in console:

./manage.py test --tag=fast -k

I got:

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

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

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

example module structure:

├── admin.py
├── __init__.py
├── migrations
├── models.py
├── tests
│   ├── __init__.py
│   ├── tests.py
│   └── test_views.py
├── urls.py
└── views.py
like image 873
a.jelly Avatar asked Jun 08 '17 07:06

a.jelly


People also ask

How do I run a test in Django?

With Django’s test-execution framework and assorted utilities, you can simulate requests, insert test data, inspect your application’s output and generally verify your code is doing what it should be doing. The preferred way to write tests in Django is using the unittest module built-in to the Python standard library.

What testing framework should I use with Django?

You can also use any other Python test framework; Django provides an API and tools for that kind of integration. They are described in the Using different testing frameworks section of Advanced testing topics.

What is unittest in Django?

Django provides a test framework with a small hierarchy of classes that build on the Python standard unittest library. Despite the name, this test framework is suitable for both unit and integration tests. The Django framework adds API methods and tools to help test web and Django-specific behavior.


2 Answers

Check that there is not a syntax error or bad import in your test files. I had a bad import and it silently failed with Ran 0 tests in 0.000s.

like image 60
Matt Avatar answered Sep 30 '22 04:09

Matt


Check if you have changed the TEST_RUNNER in your settings.py

We'd had django-nose installed. I didn't realize we were not using the default test runner and spent ages trying to figure out why my tags were not working. This post kept coming up when I was searching.

like image 30
Hybrid Avatar answered Sep 30 '22 06:09

Hybrid