Reputation: 123
I have a project built using Django and I use unittest library to do some tests, I write all the tests in tests.py file and then I run these tests with the command:
./manage.py test app
Everything works without a problem, but the tests.py file gets bigger and more complex over time, is there a simple way to split this file into a number of files so that each file contains only one type of tests?
Upvotes: 0
Views: 301
Reputation: 424
Take a look at test discovery in Django: https://docs.djangoproject.com/en/4.0/topics/testing/overview/#running-tests
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” under the current working directory.
This means that you can have files named like test_feature.py
, test_api.py
and all of these will be discovered by the management command.
The reason tests.py
is detected is that it also matches the test*.py
pattern.
Upvotes: 1