3π
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?
- 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'
20π
Summary
-
Try running for your app only:
python manage.py test YOUR_APP
-
Check in your
settings.py
file if YOUR_APP is inINSTALLED_APPS
config. -
Test method should start with
test_
, e.g.:def test_something(self): self.assertEquals(1, 2)
-
If you are using a directory called
tests
instead of thetests.py
file, check if it has a__init__.py
file inside it. -
If you are using a
tests
directory, removetests.pyc
andtests.pyo
files. (__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
7π
Try renaming your method test
to something like test_content
.
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
- Pass a list of string from Django to Javascript
- How to clear all session variables without getting logged out
- 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'
4π
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
.
...
βββ dir
βΒ Β βββ 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
3π
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