2014-03-07 54 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? –