I have just learned django these days and make a project similar to tutorial.Before i start my project,i copied tutorial code and run,but programe erred when run tests.py(tutorial05),and now it happens again.
I have added my app name in settings.py,and the errors are below: 1.run tests.py
Error
Traceback (most recent call last):
Failure: builtins.tuple: (<class 'django.core.exceptions.ImproperlyConfigured'>, ImproperlyConfigured('Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.'), <traceback object at 0x000001D2BDC66080>)
2.use ‘python manage.py test TA’ in terminal
Found 1 test(s).
System check identified no issues (0 silenced).
E
======================================================================
ERROR: djangoproject.TA (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: djangoproject.TA
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\unittest\loader.py", line 470, in _find_test_path
package = self._get_module_from_name(name)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\unittest\loader.py", line 377, in _get_module_from_name
__import__(name)
ModuleNotFoundError: No module named 'djangoproject.TA'
In your terminal where you are running your command python manage.py runserver there you can see if the environment directory is activated
something like this, here you can see (env) which is my environment folder where everything is installed for this particular project.
In addition,i can run python manage.py test TA.tests,but it can’t find my testcase
(venv) PS C:\Users\user\PycharmProjects\pythonProject\djangoproject> python manage.py test TA.tests
Found 0 test(s).
System check identified no issues (0 silenced).
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
My testcase is below,‘ssex’ is limited CharField(max_length=1)
class StudentModelTest(TestCase):
def judgesex(self):
student=Student(sno='001',sname='ggg',sage=23,ssex='Male',sbirth='2000-09-19')
self.assertIsInstance(student,Student)
When you run your tests, the default behavior of the test utility is to find all the test cases (that is, subclasses of unittest.TestCase) in any file whose name begins with test , automatically build a test suite out of those test cases, and run that suite.