gpt4 book ai didi

django pytest 没有按预期工作

转载 作者:行者123 更新时间:2023-12-04 16:45:40 33 4
gpt4 key购买 nike

我正在尝试使用 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 ==========================================================================

最佳答案

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_djangopy.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

关于django pytest 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22254523/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com