我正在尝试在Jython上使用pytest。我一开始就陷入困境。
我已经使用easy_install成功安装了pytest包:
$ ./jython easy_install pytest
当我尝试从此page运行示例时,出现问题。我收到了一个非常长的失败报告,就像下面的报道一样。有没有人知道为什么会这样?
py.test-的jython
=============================测试会话开始=============== =============== platform java1.6.0_37 - Python 2.5.3 - pytest-2.3.2 收集了1件物品
test_sample.py F
=================================== FAILURES =========== ======================== 的 _ __ _ __ _ __ _ __ _ __ _ _ 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:
source ='assert func(3)== 5',frame = should_fail = True
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 =&lt; _pytest.assertion.newinterpret.DebugInterpreter object at 0x4&gt; name = Name
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 =&lt; _pytest.assertion.newinterpret.DebugInterpreter object at 0x4&gt; node = Name
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:无法处理名称
../jython2.5.3 / Lib / site-packages / pytest-2.3.2-py2.5.egg / _pytest / assertion / newinterpret.py:134:AssertionError =========================== 1在0.55秒内失败================== =========
答案 0 :(得分:3)
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的断言。