我正在尝试使用pytest-django。我认为它安装正确:
sudo pip install --upgrade pytest-django
Requirement already up-to-date: pytest-django in /usr/local/lib/python2.6/dist-packages
然而:
py.test --ds myproj.settings_module
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --ds
有什么问题?如何检查是否安装了django-pytest?
更多信息
$ which py.test
/usr/local/bin/py.test
$ py.test --version
This is pytest version 2.5.2, imported from /usr/local/lib/python2.6/dist-packages/pytest.pyc
更多信息(2)
$ which python
/usr/bin/python
$ python
Python 2.7.3 (default, Jan 2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytest_django
>>>
$ py.test --traceconfig
PLUGIN registered: <_pytest.python.FixtureManager instance at 0x8fa0d6c>
======================================================================== test session starts =========================================================================
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2
using: pytest-2.5.2 pylib-1.4.20
active plugins:
helpconfig : /usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.pyc
pytestconfig : <_pytest.config.Config object at 0x8ce0f6c>
runner : /usr/local/lib/python2.7/dist-packages/_pytest/runner.pyc
unittest : /usr/local/lib/python2.7/dist-packages/_pytest/unittest.pyc
pastebin : /usr/local/lib/python2.7/dist-packages/_pytest/pastebin.pyc
skipping : /usr/local/lib/python2.7/dist-packages/_pytest/skipping.pyc
genscript : /usr/local/lib/python2.7/dist-packages/_pytest/genscript.pyc
session : <Session 'delme'>
tmpdir : /usr/local/lib/python2.7/dist-packages/_pytest/tmpdir.pyc
capture : /usr/local/lib/python2.7/dist-packages/_pytest/capture.pyc
terminalreporter : <_pytest.terminal.TerminalReporter instance at 0x8df44cc>
assertion : /usr/local/lib/python2.7/dist-packages/_pytest/assertion/__init__.pyc
mark : /usr/local/lib/python2.7/dist-packages/_pytest/mark.pyc
terminal : /usr/local/lib/python2.7/dist-packages/_pytest/terminal.pyc
main : /usr/local/lib/python2.7/dist-packages/_pytest/main.pyc
nose : /usr/local/lib/python2.7/dist-packages/_pytest/nose.pyc
python : /usr/local/lib/python2.7/dist-packages/_pytest/python.pyc
146879340 : <_pytest.config.PytestPluginManager object at 0x8c1336c>
recwarn : /usr/local/lib/python2.7/dist-packages/_pytest/recwarn.pyc
funcmanage : <_pytest.python.FixtureManager instance at 0x8fa0d6c>
monkeypatch : /usr/local/lib/python2.7/dist-packages/_pytest/monkeypatch.pyc
resultlog : /usr/local/lib/python2.7/dist-packages/_pytest/resultlog.pyc
capturemanager : <_pytest.capture.CaptureManager instance at 0x8df972c>
junitxml : /usr/local/lib/python2.7/dist-packages/_pytest/junitxml.pyc
doctest : /usr/local/lib/python2.7/dist-packages/_pytest/doctest.pyc
pdb : /usr/local/lib/python2.7/dist-packages/_pytest/pdb.pyc
collected 0 items
========================================================================== in 0.00 seconds ==========================================================================
答案 0 :(得分:2)
py.test文档建议使用py.test --traceconfig
来确定安装了哪些插件。 (来源:http://pytest.org/latest/plugins.html#finding-out-which-plugins-are-active)
作为一个完整性检查,我会确保您可以在Python提示符下导入pytest_django
。
$ which python
// Expect this to be /usr/local/bin/python
$ python
>>> import pytest_django
至少,您在初始问题和“更多信息(2)”部分之间使用了两个版本的Python。请注意首先路径是以/usr/local/lib/python2.6/
开头,然后是/usr/local/lib/python2.7/
开头的?这很奇怪,这样的不匹配可以解释为什么你可以导入pytest_django
但py.test
没有看到插件安装。
如果可能的话,我建议使用virtualenv
这样的环境问题。
这是一个关于如何入门的好教程:http://www.pythonforbeginners.com/basics/how-to-use-python-virtualenv
试试这个:
sudo pip install virtualenv
virtualenv env --no-site-packages --python=python2.6 // Can be python2.7 too.
source env/bin/activate
pip install pytest-django // Should pull in Django and pytest dependencies.
py.test --traceconfig