我开始阅读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固定装置创建httpbin固定装置?
我错过了什么?
最佳答案
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 [email protected]: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
(注意:
pip install mock
仅对于Python