2👍
I just do this tutorial.
Edit: after django 1.6, the test discovery mechanism changed. You just have to create a folder tests
with an __init__.py
file inside, and put your test files there.
Your test files should match test*.py
pattern.
2👍
In your example, if you run manage.py test app.TestBananas
then you can run that specific test.
You can get everything working by making sure all your tests are imported into __init__.py
but when you have lots of tests this becomes difficult to manage. If you want to run the tests in PyCharm then django-nose isn’t an option.
To make this easier we can have the test suite automatically find all tests in the tests package. Just put this in __init__.py
(Be sure to replace “appname”):
def suite():
return unittest.TestLoader().discover("appname.tests", pattern="*.py")
This still won’t allow us to run specific tests. To do that you’ll need to add this code at the top of __init__.py
:
import pkgutil
import unittest
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
module = loader.find_module(module_name).load_module(module_name)
for name in dir(module):
obj = getattr(module, name)
if isinstance(obj, type) and issubclass(obj, unittest.case.TestCase):
exec ('%s = obj' % obj.__name__)
Now you can run all your tests via manage.py test app
or specific ones via manage.py test app.TestApples
- [Django]-Django, how to parse a single form field (HTML) without a for loop
- [Django]-Django: object needs to have a value for field "…" before this many-to-many relationship can be used
- [Django]-Django catching any url?
- [Django]-How can i split up a large django-celery tasks.py module into smaller chunks?
- [Django]-Creating a Django admin account: null value of password
0👍
Did you try renaming your test files to “test_foo.py”, instead of “foo.py”, for example?
- [Django]-Django Test Client does not create database entries
- [Django]-How to get local datetime from django model DateTimeField?
- [Django]-Django: how to filter on subset of many-to-many field?
- [Django]-How can I pass additional args in as_view in Django REST framework
- [Django]-Is client side validation nessesary in Django?