gpt4 book ai didi

jython - 将 pytest 与 Jython 一起使用

转载 作者:行者123 更新时间:2023-12-05 01:18:07 26 4
gpt4 key购买 nike

我正在尝试在 Jython 上使用 pytest。我一开始就被卡住了。

我已经使用easy_install成功安装了pytest包:

$ ./jython easy_install pytest

当我尝试从这个 page 运行示例时,事情出错了。我收到了一份非常长的失败报告,如下所示。有人知道为什么会这样吗?

py.test-jython

============================ 测试 session 开始 ================== ============
平台 java1.6.0_37 -- Python 2.5.3 -- pytest-2.3.2
收集到 1 件元素

test_sample.py F

====================================失败============== ======================
_________________ test_answer __________________
def test_answer():

  assert func(3) == 5


test_sample.py:5:

self = AssertionError()
def __init__(self, *args):
BuiltinAssertionError.__init__(self, *args)
if args:
try:
self.msg = str(args[0])
except py.builtin._sysex:
raise
except:
self.msg = "<[broken __repr__] %s at %0xd>" %(
args[0].__class__, id(args[0]))
else:
f = py.code.Frame(sys._getframe(1))
try:
source = f.code.fullsource
if source is not None:
try:
source = source.getstatement(f.lineno, assertion=True)
except IndexError:
source = None
else:
source = str(source.deindent()).strip()
except py.error.ENOENT:
source = None
# this can also occur during reinterpretation, when the
# co_filename is set to "<run>".
if source:

          self.msg = reinterpret(source, f, should_fail=True)


../jython2.5.3/Lib/site-packages/pytest-2.3.2-py2.5.egg/_pytest/assertion/reinterpret.py:32:

源 = 'assert func(3) == 5', 框架 =
should_fail = 真
def interpret(source, frame, should_fail=False):
mod = ast.parse(source)
visitor = DebugInterpreter(frame)
try:

      visitor.visit(mod)


../jython2.5.3/Lib/site-packages/pytest-2.3.2-py2.5.egg/_pytest/assertion/newinterpret.py:49:

.
.
.

self = <_pytest.assertion.newinterpret.DebugInterpreter 对象在 0x4>
姓名 = 姓名
def visit_Name(self, name):

  explanation, result = self.generic_visit(name)


../jython2.5.3/Lib/site-packages/pytest-2.3.2-py2.5.egg/_pytest/assertion/newinterpret.py:147:

self = <_pytest.assertion.newinterpret.DebugInterpreter 对象在 0x4>
节点 = 名称
def generic_visit(self, node):
# Fallback when we don't have a special implementation.
if _is_ast_expr(node):
mod = ast.Expression(node)
co = self._compile(mod)
try:
result = self.frame.eval(co)
except Exception:
raise Failure()
explanation = self.frame.repr(result)
return explanation, result
elif _is_ast_stmt(node):
mod = ast.Module([node])
co = self._compile(mod, "exec")
try:
self.frame.exec_(co)
except Exception:
raise Failure()
return None, None
else:

      raise AssertionError("can't handle %s" %(node,))

E AssertionError: can't handle Name



../jython2.5.3/Lib/site-packages/pytest-2.3.2-py2.5.egg/_pytest/assertion/newinterpret.py:134: AssertionError
============================ 1 次失败在 0.55 秒内 ================== ==========

最佳答案

Pytest 有解决 jython 缺少 AST 实现的方法,请参阅 issue1479 .我只是将 pytest 方面的解决方法扩展到 jython-2.5.3。您可以使用以下命令安装 pytest 的开发候选人:

pip install -i http://pypi.testrun.org -U pytest

并且应该至少使用“py.test-jython --version”获得版本 2.3.4.dev1 并获得使用 jython-2.5.3 的断言。

关于jython - 将 pytest 与 Jython 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13250258/

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