Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我执行UNITEST命令时;python3-m单元测试文件路径/filename.py“;它显示配置不正确的错误_Python_Python 3.x_Django_Unit Testing - Fatal编程技术网

当我执行UNITEST命令时;python3-m单元测试文件路径/filename.py“;它显示配置不正确的错误

当我执行UNITEST命令时;python3-m单元测试文件路径/filename.py“;它显示配置不正确的错误,python,python-3.x,django,unit-testing,Python,Python 3.x,Django,Unit Testing,当我执行单元测试命令时:python3-m unittest filepath/filename.py它抛出了一个配置不正确的错误,如果有人能帮忙,我们将不胜感激 错误: django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJA

当我执行单元测试命令时:
python3-m unittest filepath/filename.py
它抛出了一个配置不正确的错误,如果有人能帮忙,我们将不胜感激

错误:

django.core.exceptions.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.

您需要设置运行单元测试所需的设置文件

在Linux上

$ export DJANGO_SETTINGS_MODULE=your_setting

如果运行
python-m django unittestfilepath/filename.py,请阅读此

,因为当您作为子命令运行
django
时,环境变量已设置