未找到夹具 'httpbin'
fixture 'httpbin' not found
我开始阅读 python requests
图书馆。
我做的第一件事是 运行 在本地进行 pytest。
然后我收到此错误消息:
@pytest.fixture
def httpbin(httpbin):
fixture 'httpbin' not found
available fixtures: tmpdir_factory, httpbin_secure, pytestconfig, httpbin, cov, cache, recwarn, monkeypatch, record_xml_property, capfd, capsys, tmpdir
use 'py.test --fixtures [testpath]' for help on them.
在测试模块的 conftest.py
文件中,它尝试创建一个夹具:
@pytest.fixture
def httpbin(httpbin):
return prepare_url(httpbin)
如何使用 httpbin fixture 创建 httpbin fixture?
我错过了什么?
httpbin
夹具由 pytest-httpbin
包提供。因此,您需要确保在 运行 测试之前为 运行 测试/构建文档 安装了所需的 依赖项。
这基本上等于pip install -r requirements.txt
。
更详细一点,将所有内容安装到 virtualenv 中:
# Create the virtualenv
$ virtualenv-2.7 --no-site-packages requests-env
$ cd requests-env
$ . bin/activate
# Make sure your venv's version of setuptools is up to date
(requests-env) $ pip install -U setuptools
# Clone a copy of the requests module
(requests-env) $ mkdir src
(requests-env) $ cd src/
(requests-env) $ git clone git@github.com:kennethreitz/requests.git
# Install required dependencies
(requests-env) $ cd requests/
(requests-env) $ pip install -r requirements.txt
(requests-env) $ pip install mock
# Run tests
(requests-env) $ py.test
(注意:只有 Python < 3.3 才需要 pip install mock
)
我开始阅读 python requests
图书馆。
我做的第一件事是 运行 在本地进行 pytest。
然后我收到此错误消息:
@pytest.fixture
def httpbin(httpbin):
fixture 'httpbin' not found
available fixtures: tmpdir_factory, httpbin_secure, pytestconfig, httpbin, cov, cache, recwarn, monkeypatch, record_xml_property, capfd, capsys, tmpdir
use 'py.test --fixtures [testpath]' for help on them.
在测试模块的 conftest.py
文件中,它尝试创建一个夹具:
@pytest.fixture
def httpbin(httpbin):
return prepare_url(httpbin)
如何使用 httpbin fixture 创建 httpbin fixture? 我错过了什么?
httpbin
夹具由 pytest-httpbin
包提供。因此,您需要确保在 运行 测试之前为 运行 测试/构建文档 安装了所需的 依赖项。
这基本上等于pip install -r requirements.txt
。
更详细一点,将所有内容安装到 virtualenv 中:
# Create the virtualenv
$ virtualenv-2.7 --no-site-packages requests-env
$ cd requests-env
$ . bin/activate
# Make sure your venv's version of setuptools is up to date
(requests-env) $ pip install -U setuptools
# Clone a copy of the requests module
(requests-env) $ mkdir src
(requests-env) $ cd src/
(requests-env) $ git clone git@github.com:kennethreitz/requests.git
# Install required dependencies
(requests-env) $ cd requests/
(requests-env) $ pip install -r requirements.txt
(requests-env) $ pip install mock
# Run tests
(requests-env) $ py.test
(注意:只有 Python < 3.3 才需要 pip install mock
)