Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.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
Python 将测试文件转换为带有_init__u; py.py的包时出现问题_Python_Django - Fatal编程技术网

Python 将测试文件转换为带有_init__u; py.py的包时出现问题

Python 将测试文件转换为带有_init__u; py.py的包时出现问题,python,django,Python,Django,我将随本教程一起介绍以下内容: 当我跑步时: (tb_test)metersk:functional_tests metersky$ python test_all_users.py . ---------------------------------------------------------------------- Ran 1 test in 2.313s OK 测试按它应该的方式进行。测试是: from selenium import webdriver import uni

我将随本教程一起介绍以下内容:

当我跑步时:

(tb_test)metersk:functional_tests metersky$ python test_all_users.py
.
----------------------------------------------------------------------
Ran 1 test in 2.313s

OK
测试按它应该的方式进行。测试是:

from selenium import webdriver
import unittest


class NewVisitorTest(unittest.TestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(3)

    def tearDown(self):
        self.browser.quit()

    def test_it_worked(self):
        self.browser.get('http://localhost:8000')
        self.assertIn('Welcome to Django', self.browser.title)

if __name__ == '__main__':
    unittest.main(warnings='ignore')
但是,当我按照步骤将一个空白的
\uuuu init\uuuuuuuuuuupy.py
文件添加到目录中时,我会像这样运行测试:
python manage.py test functional\u tests

在以下故障中,我得到一个警告:

Traceback (most recent call last):
  File "/Users/metersky/code/taskbuster_project/taskbuster/settings/base.py", line 20, in get_env_variable
    return os.environ[var_name]
  File "/Users/metersky/.virtualenvs/tb_test/bin/../lib/python3.4/os.py", line 633, in __getitem__
    raise KeyError(key) from None
KeyError: 'SECRET_KEY'


  File "/Users/metersky/code/taskbuster_project/taskbuster/settings/__init__.py", line 2, in <module>
    from .base import *
  File "/Users/metersky/code/taskbuster_project/taskbuster/settings/base.py", line 31, in <module>
    SECRET_KEY = get_env_variable('SECRET_KEY')
  File "/Users/metersky/code/taskbuster_project/taskbuster/settings/base.py", line 23, in get_env_variable
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: set the SECRET_KEY environment variable

你能发布你的文件夹结构吗?另外,我不认为这是相关的,但它是
\uuu init\uuuuuuuuuuupy
,而不是
\uuuuuu init.py
。不确定这是一个输入错误还是您创建的实际文件。输入错误,现在修复并添加文件夹结构。当您运行
/manage.py test functional\u tests
?@dursk是的,tb\u dev在另一个终端运行服务器时,您可以发布您的文件夹结构吗,我不认为这是相关的,但它是
\uu init\uuuuuuuuuuuuuuuuuuuuuupy
,而不是
\uuuuuuuuuuu init.py
。不确定这是输入错误还是您创建的实际文件。输入错误,现在修复并添加文件夹结构。当您运行
/manage.py test functional\u tests
时,您处于
tb\u test
虚拟环境中?@dursk是的,tb\u dev在不同的终端上运行服务器
├── TaskBuster.sublime-project
├── TaskBuster.sublime-workspace
├── db.sqlite3
├── functional_tests
│   ├── __init__.py
│   └── test_all_users.py
├── manage.py
├── requirements
│   ├── base.txt
│   ├── development.txt
│   ├── production.txt
│   └── testing.txt
└── taskbuster
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-34.pyc
    │   ├── settings.cpython-34.pyc
    │   ├── urls.cpython-34.pyc
    │   └── wsgi.cpython-34.pyc
    ├── db.sqlite3
    ├── settings
    │   ├── __init__.py
    │   ├── __pycache__
    │   │   ├── __init__.cpython-34.pyc
    │   │   ├── base.cpython-34.pyc
    │   │   └── development.cpython-34.pyc
    │   ├── base.py
    │   ├── development.py
    │   ├── production.py
    │   ├── staging.py
    │   └── testing.py
    ├── static
    │   ├── css
    │   │   ├── bootstrap-theme.css
    │   │   ├── bootstrap-theme.css.map
    │   │   ├── bootstrap-theme.min.css
    │   │   ├── bootstrap.css
    │   │   ├── bootstrap.css.map
    │   │   ├── bootstrap.min.css
    │   │   └── main.css
    │   ├── favicon.ico
    │   ├── fonts
    │   │   ├── glyphicons-halflings-regular.eot
    │   │   ├── glyphicons-halflings-regular.svg
    │   │   ├── glyphicons-halflings-regular.ttf
    │   │   └── glyphicons-halflings-regular.woff
    │   ├── img
    │   └── js
    │       ├── main.js
    │       └── vendor
    │           ├── bootstrap.js
    │           ├── bootstrap.min.js
    │           ├── jquery-1.11.2.min.js
    │           ├── modernizr-2.8.3-respond-1.4.2.min.js
    │           └── npm.js
    ├── templates
    │   ├── 404.html
    │   ├── base.html
    │   ├── humans.txt
    │   └── robots.txt
    ├── urls.py
    └── wsgi.py