2014-03-07 119 views
2

我正在尝试使用pytest-django。我认为这是正确安装:django pytest不按预期工作

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

你有没有设置'TEST_RUNNER =“django_pytest.test_runner.TestRunner''并添加'django_pytest'到'INSTALLED_APPS' ? – alecxe

+0

不......我应该把它放在设置中吗? –

+0

哎呀,不,这是你正在使用的一个不同的包,抱歉,不相关。 – alecxe

回答

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 
+0

我在问题中添加了更多信息(2)。导入pytest_django查找软件包,但--traceconfig未列出与django相关的任何内容。 –

+0

我已经更新了我的答案。希望使用'virtualenv'是你的用例的可能性,否则我们可以继续挖掘。 –

+0

是的,用virtualenv它似乎工作!我收到一条错误消息,因为它找不到我的django设置。但是:是不是不可能*不使用virtualenv? –