【发布时间】:2016-11-23 07:59:34
【问题描述】:
实际上我正在尝试在 Eclipse 中使用 python 框架(带有 PyDev 插件) - 该框架是在 PyCharm IDE 中设计的,我们在其中进行一些配置,如下面的屏幕截图所示:
我已经尝试搜索参考链接,但到目前为止没有运气。那么有人可以帮助我如何在 Eclipse 中配置 Target、Keywords、Options 参数吗?
********添加一些附加信息********
在此,我按照说明添加了一些基本的 sn-p -
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 "测试"
============================== 测试会话开始 =============== ==============平台 win32 -- Python 2.7.12 -- pytest-2.5.1 插件:xdist、xdist、xdist 收集3项
test_sample.py ...
=========================== 3 在 0.05 秒内通过 ================ ===========
但是当我尝试通过 Eclipse PyDev 运行它时它不起作用,请注意我已将 PyUnit 测试运行程序选项更改为 Py.test 运行程序,如 blog 中指定的那样。我还尝试在 Run > Run Configurations > Arguments 中提供 -k "test" 选项,但出现如下突然异常 - 请帮助!
Traceback(最近一次调用最后一次):文件 "D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc\runfiles.py", 第 241 行,在 main() 文件 "D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc\runfiles.py", 第 233 行,主要 返回 pytest.main(argv) 文件“C:\Python27\lib\site-packages_pytest\config.py”,第 18 行,在 main config = _prepareconfig(args, plugins) 文件“C:\Python27\lib\site-packages_pytest\config.py”,第 62 行,在 _prepareconfig pluginmanager=pluginmanager, args=args) 文件“C:\Python27\lib\site-packages_pytest\core.py”,第 376 行,在 call 返回 self._docall(methods, kwargs) 文件“C:\Python27\lib\site-packages_pytest\core.py”,第 387 行,在 _docall res = mc.execute() 文件“C:\Python27\lib\site-packages_pytest\core.py”,第 288 行,在执行中 res = 方法(**kwargs)文件“C:\Python27\lib\site-packages_pytest\helpconfig.py”,第 25 行,在 pytest_cmdline_parse config = multicall.execute() 文件“C:\Python27\lib\site-packages_pytest\core.py”,第 288 行,在执行中 res = 方法(**kwargs)文件“C:\Python27\lib\site-packages_pytest\config.py”,第 617 行,在 pytest_cmdline_parse self.parse(args) 文件“C:\Python27\lib\site-packages_pytest\config.py”,第 710 行,解析中 self._preparse(args) 文件“C:\Python27\lib\site-packages_pytest\config.py”,第 686 行,在 _preparse self.pluginmanager.consider_preparse(args) 文件“C:\Python27\lib\site-packages_pytest\core.py”,第 185 行,在 考虑预解析 self.consider_pluginarg(opt2) 文件“C:\Python27\lib\site-packages_pytest\core.py”,第 195 行,在 考虑插件参数 self.import_plugin(arg) 文件“C:\Python27\lib\site-packages_pytest\core.py”,第 214 行,在 导入插件 mod = importplugin(modname) 文件“C:\Python27\lib\site-packages_pytest\core.py”,第 269 行,在 导入插件 导入(importspec)文件“D:\eclipse\plugins\org.python.pydev_5.1.2.201606231256\pysrc_pydev_runfiles\pydev_runfiles_pytest2.py”, 第 284 行,在 @pytest.hookimpl(hookwrapper=True) AttributeError: 'module' object has no attribute 'hookimpl'
【问题讨论】:
-
似乎 PyDev 将所有选项都放在了一个地方;请参阅pydev.org/manual_adv_pyunit.html,它还链接到 py.test 文档。
-
不,它没有锻炼……我尝试过像 -k=sanity --project=city1 --env=city1_sit --translation=ct 这样的更新。 .. 但出现了一些错误,例如 AttributeError: 'module' object has no attribute 'hookimpl'
-
那么请edit 用minimal reproducible example 提问。
-
@jonrsharpe - 我理解你的问题,但老实说,我并不是将框架缩小到最小的 sn-p 并分享以供参考的专家。但我的问题类似于link,他在那里要求 PyCharm。它也可能提供类似的细节,但至少以不同的方式!
-
您至少可以提供回溯以告诉我们在哪里引发了错误。如果它只是来自 py.test,那么在进行测试之前,您实际编写的代码都没有相关性。但我不能从这里看出,您需要尝试设置一个干净的项目并使用最少的代码移动,直到它复制错误。事实上,您应该已经这样做了,这是基本的调试。
标签: python eclipse pycharm pydev