I am using Django==1.7c2
and I wan't to say to Django
find and run all tests in my project. I just created a folder with __init__.py
which is named tests
instead of putting all in tests.py.
Here is my file structure;
my_project/apps/my_app/
├── __init__.py
├── tests
├── __init__.py
├── my_first_test.py
├── my_second_test.py
├── ....
├── ....
└── ....
and my __init__.py
in tests file is like;
from my_first_test import *
from my_second_test import *
I thought that Django
would recognise my test folder
initially, but when I run just this command;
python manage.py test
There is no test case that Django find to run.
$ python manage.py test
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
I must run the tests for specific application in my project like;
python manage.py test my_project.apps.my_app.tests
It results;
----------------------------------------------------------------------
Ran 7 tests in 1.432s
OK
Destroying test database for alias 'default'...
I really don't like it, because I need to run all tests in all application in my project at once instead of running them one by one. I don't know what am I missing.
Is there a way to say Django find and run all test at once in all applications in the project?
Thank You!
I have the apps in INSTALLED_APPS
in my setting.py
Open /catalog/tests/test_models.py.from django. test import TestCase # Create your tests here. Often you will add a test class for each model/view/form you want to test, with individual methods for testing specific functionality.
The preferred way to write tests in Django is using the unittest module built-in to the Python standard library. This is covered in detail in the Writing and running tests document. You can also use any other Python test framework; Django provides an API and tools for that kind of integration.
If you're using the PyCharm IDE, you can run unittest or pytest by following these steps: In the Project tool window, select the tests directory. On the context menu, choose the run command for unittest . For example, choose Run 'Unittests in my Tests…'.
Writing tests Django's unit tests use a Python standard library module: unittest . This module defines tests using a class-based approach. When you run your tests, the default behavior of the test utility is to find all the test cases (that is, subclasses of unittest.
Try this:
$ ./manage.py test --pattern="*_test.py"
Test discovery is based on the unittest module’s built-in test discovery. By default, this will discover tests in any file named “test*.py”.
Note
By the way you don't need import TestCases in __init__.py
file if you are using standard test discovery (Django start using built-in test discovery since 1.6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With