👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
The Django documentation (http://docs.djangoproject.com/en/1.3/topics/testing/#running-tests) says that you can run individual test cases by specifying them:
$ ./manage.py test animals.AnimalTestCase
This assumes that you have your tests in a tests.py file in your Django application. If this is true, then this command works like expected.
I have my tests for a Django application in a tests directory:
my_project/apps/my_app/
├── __init__.py
├── tests
│ ├── __init__.py
│ ├── field_tests.py
│ ├── storage_tests.py
├── urls.py
├── utils.py
└── views.py
The tests/__init__.py
file has a suite() function:
import unittest
from my_project.apps.my_app.tests import field_tests, storage_tests
def suite():
tests_loader = unittest.TestLoader().loadTestsFromModule
test_suites = []
test_suites.append(tests_loader(field_tests))
test_suites.append(tests_loader(storage_tests))
return unittest.TestSuite(test_suites)
To run the tests I do:
$ ./manage.py test my_app
Trying to specify an individual test case raises an exception:
$ ./manage.py test my_app.tests.storage_tests.StorageTestCase
...
ValueError: Test label "my_app.tests.storage_tests.StorageTestCase" should be of the form app.TestCase or app.TestCase.test_method
I tried to do what the exception message said:
$ ./manage.py test my_app.StorageTestCase
...
ValueError: Test label "my_app.StorageTestCase" does not refer to a test
How do I specify an individual test case when my tests are in multiple files?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Running a specific test case in Django when your app has a tests directory, check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Running a specific test case in Django when your app has a tests directory
- Deutsch Running a specific test case in Django when your app has a tests directory
- Français Running a specific test case in Django when your app has a tests directory
- Español Running a specific test case in Django when your app has a tests directory
- Türk Running a specific test case in Django when your app has a tests directory
- Русский Running a specific test case in Django when your app has a tests directory
- Português Running a specific test case in Django when your app has a tests directory
- Polski Running a specific test case in Django when your app has a tests directory
- Nederlandse Running a specific test case in Django when your app has a tests directory
- 中文 Running a specific test case in Django when your app has a tests directory
- 한국어 Running a specific test case in Django when your app has a tests directory
- 日本語 Running a specific test case in Django when your app has a tests directory
- हिन्दी Running a specific test case in Django when your app has a tests directory
Paris | 2023-01-27
Simply put and clear. Thank you for sharing. Running a specific test case in Django when your app has a tests directory and other issues with io Python module was always my weak point 😁. Checked yesterday, it works!
Rome | 2023-01-27
Thanks for explaining! I was stuck with Running a specific test case in Django when your app has a tests directory for some hours, finally got it done 🤗. Will get back tomorrow with feedback
Warsaw | 2023-01-27
Maybe there are another answers? What Running a specific test case in Django when your app has a tests directory exactly means?. Will use it in my bachelor thesis