There is something not quite right if you are getting the same result after renaming the file to
tests.py. How are you running the tests? Are you doing so from the command line or have you set up a custom run target using Eclipse? Please try it from the command line if you haven’t already.
Also fire up Django shell (
python manage.py shell) and import your tests module.
from MyProj.forum.tests import SimpleTest
Does the import work correctly?
You´ll need to use the prefix
test_ for each test method.
- Django form.is_valid() always false
- Django CSRF cookie HttpOnly
- Commit manually in Django data migration
- Django-filter: TypeError at /goods/ __init__() got an unexpected keyword argument 'name'
Try running for your app only:
python manage.py test YOUR_APP
Check in your
settings.pyfile if YOUR_APP is in
Test method should start with
def test_something(self): self.assertEquals(1, 2)
If you are using a directory called
testsinstead of the
tests.pyfile, check if it has a
__init__.pyfile inside it.
If you are using a
__pycache__dir for Python3)
- ValueError: "needs to have a value for field "id" before this many-to-many relationship can be used"
- Django template extends not working
Try renaming your method
test to something like
I believe the test runner will run all methods named
test_* (see the python docs for organising test code. Django’s
TestCase is a subclass of
unittest.TestCase, so the same rules should apply.
- Django 2.0: sqlite IntegrityError: FOREIGN KEY constraint failed
- How to clear all session variables without getting logged out
You have to name it
- Django + S3 (boto) + Sorl Thumbnail: Suggestions for optimisation
- Missing distribution spec error using pip install from requirements
- How to solve the a celery worker configuration with keyword argument namespace='"CELERY"error in the celery file
- Django 'function' object has no attribute 'objects'
- 'str' object has no attribute 'get'
After some time spent in searching I did not find anyone suggesting this, so I will share it as a late answer.
In my case I have my
manage.py in the root directory eg
│ ├── project_name
│ ├── manage.py
│ ├── media
│ ├── app1
│ ├── static
│ ├── staticfiles
│ ├── templates
│ └── app2
so I found that the test command has the option to provide project which tests’ to run. In my case I had to do this
python project_name/manage.py test ./project_name/
This successfully ran my tests.
- How does a python web server overcomes GIL
- How do you add a non-editable field to a custom admin form in Django
- How to print pretty JSON on a html page from a django template?
- Django-zappa: Error loading psycopg2 module: libpq.so.5: cannot open shared object file: No such file or directory
I had tried all these things but I neglected to add the __init__.py file in the tests directory that I created to hold all my tests and Django couldn’t find it.
- Alternatives to Django for Python based Web Development?
- Why is serving static files insecure
- Django South migration to different databases
- Testing a custom Django template filter
- How to create new resource with foreign key in TastyPie