Solved - It was a simple naming convention error after all - i had failed to start the def within the test python file with `test_β. I had mistakenly only associated that with the files not the function names - many thanks to Suttonium
Hi,
I am new to Django, I have gone through the tutorial, more using it as a template to build an early version of the site I am working on. It has worked fine, and I have got my site up and running ok using the inbuilt server, however what has not worked is using the test functionality.
I have read the other threads on here, and am really not sure what it could be. I see there have been another thread or two where people started again and then got round their problems, but I have been through everything I can think of. I am wondering if I am missing some naming convention β¦ who knows β¦ hopefully you
I have a project folder with a single app in it and i initially put a test file into the app root director. This just resulted in 0 tests being run, no matter what arguments i gave the command line (including/excluding app) etc.
I then read up a bit and whilst that should of worked, I moved my test file to a folder tests under the app folder and added an init.py file to the test folder before adding a line to import all from the tests.py file.
I now get the following error:
% python3.8 manage.py test appname -v3
Skipping setup of unused database(s): default.
System check identified no issues (0 silenced).
appname.tests (unittest.loader._FailedTest) ... ERROR
======================================================================
ERROR: appname.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: appname.tests
Traceback (most recent call last):
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/loader.py", line 470, in _find_test_path
package = self._get_module_from_name(name)
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/Users/username/git/django/sitename/appname/tests/__init__.py", line 1, in <module>
from tests.py import *
ModuleNotFoundError: No module named 'tests'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
The test file looks like this:
from django.test import TestCase
from django.test import Client
from django.urls import reverse
class testmy(TestCase):
def index_page_loads_ok(self):
print("hello")
I removed everything I could to make it as simple as possible.
The init.py within the appname/tests folder looks like this
from tests.py import *
I am running on Mac using Python 3.85.
My current folder structure below the project folder looks like this:
βββ db.sqlite3
βββ manage.py
βββ appname
β βββ __init__.py
β βββ admin.py
β βββ apps.py
β βββ migrations
β β βββ 0001_initial.py
β β βββ __init__.py
β βββ models.py
β βββ static
β β βββ appname
β β βββ graphics
β β β βββ addsymbolround.png
β β β βββ documentation-photo.jpg
β β β βββ background.jpeg
β β βββ styles.css
β βββ templates
β β βββ appname
β β βββ entities.html
β β βββ index.html
β βββ tests
β β βββ __init__.py
β β βββ tests.py
β βββ urls.py
β βββ views.py
βββ sitename
βββ asgi.py
βββ settings.py
βββ urls.py
βββ wsgi.py
It feels like it is a simple mistake I have made but I just canβt figure it out so any help would be appreciated.