在 eclipse 中配置 Python 项目
Configuring Python project in eclipse
实际上,我正在尝试在 Eclipse 中使用 python 框架(带有 PyDev 插件)- 该框架是在 PyCharm IDE 中设计的,我们在其中进行了一些配置,如屏幕截图如下:
我试过搜索参考链接,但到目前为止还没有成功。那么有人可以帮助我如何在 Eclipse 中配置 Target、Keywords、Options 参数吗?
******** 添加一些附加信息 ********
在此,我将按照说明添加一些基本片段 -
import pytest
@pytest.mark.test
def test_method():
print "test method"
class TestClass:
def test_one(self):
x = "this"
assert 'h' in x
def test_two(self):
x = "hello"
assert 'o' in x
当我尝试使用以下命令 运行 通过命令提示符
它工作正常
$ py.test -k "test"
============================= test session starts ============================= platform win32 -- Python 2.7.12 -- pytest-2.5.1 plugins: xdist, xdist, xdist collected 3 items
test_sample.py ...
========================== 3 passed in 0.05 seconds ===========================
但是当我尝试通过 Eclipse PyDev 运行 它时它不起作用,请注意我已经将 PyUnit 测试 运行ner 选项更改为 Py.test 运行ner 在 blog 中指定。我还尝试在 运行 > 运行 Configurations > Arguments 中提供 -k "test"
选项,但出现如下突然异常 - 请帮助!
Traceback (most recent call last): File
"D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc\runfiles.py",
line 241, in
main() File "D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc\runfiles.py",
line 233, in main
return pytest.main(argv) File "C:\Python27\lib\site-packages_pytest\config.py", line 18, in main
config = _prepareconfig(args, plugins) File "C:\Python27\lib\site-packages_pytest\config.py", line 62, in
_prepareconfig
pluginmanager=pluginmanager, args=args) File "C:\Python27\lib\site-packages_pytest\core.py", line 376, in call
return self._docall(methods, kwargs) File "C:\Python27\lib\site-packages_pytest\core.py", line 387, in _docall
res = mc.execute() File "C:\Python27\lib\site-packages_pytest\core.py", line 288, in execute
res = method(**kwargs) File "C:\Python27\lib\site-packages_pytest\helpconfig.py", line 25, in
pytest_cmdline_parse
config = multicall.execute() File "C:\Python27\lib\site-packages_pytest\core.py", line 288, in execute
res = method(**kwargs) File "C:\Python27\lib\site-packages_pytest\config.py", line 617, in
pytest_cmdline_parse
self.parse(args) File "C:\Python27\lib\site-packages_pytest\config.py", line 710, in parse
self._preparse(args) File "C:\Python27\lib\site-packages_pytest\config.py", line 686, in
_preparse
self.pluginmanager.consider_preparse(args) File "C:\Python27\lib\site-packages_pytest\core.py", line 185, in
consider_preparse
self.consider_pluginarg(opt2) File "C:\Python27\lib\site-packages_pytest\core.py", line 195, in
consider_pluginarg
self.import_plugin(arg) File "C:\Python27\lib\site-packages_pytest\core.py", line 214, in
import_plugin
mod = importplugin(modname) File "C:\Python27\lib\site-packages_pytest\core.py", line 269, in
importplugin
import(importspec) File "D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc_pydev_runfiles\pydev_runfiles_pytest2.py",
line 284, in
@pytest.hookimpl(hookwrapper=True) AttributeError: 'module' object has no attribute 'hookimpl'
嗯,你能更新你的 pytest 版本并重试吗?您使用的是哪个 pytest 版本?
即似乎 PyDev 现在需要 pytest 2.7 及更高版本(hookwrapper:围绕其他挂钩执行是 2.7 版中的新功能,来自:http://docs.pytest.org/en/latest/writing_plugins.html)。
请注意,pytest 2.7 是从 2015 年 3 月 26 日开始的,所以它已经比较老了。
实际上,我正在尝试在 Eclipse 中使用 python 框架(带有 PyDev 插件)- 该框架是在 PyCharm IDE 中设计的,我们在其中进行了一些配置,如屏幕截图如下:
我试过搜索参考链接,但到目前为止还没有成功。那么有人可以帮助我如何在 Eclipse 中配置 Target、Keywords、Options 参数吗?
******** 添加一些附加信息 ********
在此,我将按照说明添加一些基本片段 -
import pytest
@pytest.mark.test
def test_method():
print "test method"
class TestClass:
def test_one(self):
x = "this"
assert 'h' in x
def test_two(self):
x = "hello"
assert 'o' in x
当我尝试使用以下命令 运行 通过命令提示符
它工作正常$ py.test -k "test"
============================= test session starts ============================= platform win32 -- Python 2.7.12 -- pytest-2.5.1 plugins: xdist, xdist, xdist collected 3 items
test_sample.py ...
========================== 3 passed in 0.05 seconds ===========================
但是当我尝试通过 Eclipse PyDev 运行 它时它不起作用,请注意我已经将 PyUnit 测试 运行ner 选项更改为 Py.test 运行ner 在 blog 中指定。我还尝试在 运行 > 运行 Configurations > Arguments 中提供 -k "test"
选项,但出现如下突然异常 - 请帮助!
Traceback (most recent call last): File "D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc\runfiles.py", line 241, in main() File "D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc\runfiles.py", line 233, in main return pytest.main(argv) File "C:\Python27\lib\site-packages_pytest\config.py", line 18, in main config = _prepareconfig(args, plugins) File "C:\Python27\lib\site-packages_pytest\config.py", line 62, in _prepareconfig pluginmanager=pluginmanager, args=args) File "C:\Python27\lib\site-packages_pytest\core.py", line 376, in call return self._docall(methods, kwargs) File "C:\Python27\lib\site-packages_pytest\core.py", line 387, in _docall res = mc.execute() File "C:\Python27\lib\site-packages_pytest\core.py", line 288, in execute res = method(**kwargs) File "C:\Python27\lib\site-packages_pytest\helpconfig.py", line 25, in pytest_cmdline_parse config = multicall.execute() File "C:\Python27\lib\site-packages_pytest\core.py", line 288, in execute res = method(**kwargs) File "C:\Python27\lib\site-packages_pytest\config.py", line 617, in pytest_cmdline_parse self.parse(args) File "C:\Python27\lib\site-packages_pytest\config.py", line 710, in parse self._preparse(args) File "C:\Python27\lib\site-packages_pytest\config.py", line 686, in _preparse self.pluginmanager.consider_preparse(args) File "C:\Python27\lib\site-packages_pytest\core.py", line 185, in consider_preparse self.consider_pluginarg(opt2) File "C:\Python27\lib\site-packages_pytest\core.py", line 195, in consider_pluginarg self.import_plugin(arg) File "C:\Python27\lib\site-packages_pytest\core.py", line 214, in import_plugin mod = importplugin(modname) File "C:\Python27\lib\site-packages_pytest\core.py", line 269, in importplugin import(importspec) File "D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc_pydev_runfiles\pydev_runfiles_pytest2.py", line 284, in @pytest.hookimpl(hookwrapper=True) AttributeError: 'module' object has no attribute 'hookimpl'
嗯,你能更新你的 pytest 版本并重试吗?您使用的是哪个 pytest 版本?
即似乎 PyDev 现在需要 pytest 2.7 及更高版本(hookwrapper:围绕其他挂钩执行是 2.7 版中的新功能,来自:http://docs.pytest.org/en/latest/writing_plugins.html)。
请注意,pytest 2.7 是从 2015 年 3 月 26 日开始的,所以它已经比较老了。