Using pytest with Jython

I am trying to use pytest in Jython. And I'm stuck at the very beginning.

I have successfully installed the pytest package with easy_install:

$ ./jython easy_install pytest 

When I try to run an example from this page , everything goes wrong. I get an extremely long crash report, like the one below. Does anyone know why this is happening?

py.test-jython

===================================== Starting a test session ============ === ================ platform java1.6.0_37 - Python 2.5.3 - pytest-2.3.2 collected 1 pc.

test_sample.py F

============================= FAULTS ====================== =============== _________________ test_answer __________________

 def test_answer(): 
  assert func(3) == 5 

test_sample.py►:


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 = <_pytest.assertion.newinterpret.DebugInterpreter object at 0x4> 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 = <_pytest.assertion.newinterpret.DebugInterpreter object at 0x4> 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: cannot handle name

../jython2.5.3/Lib/site-packages/pytest-2.3.2-py2.5.egg/_pytest/assertion/newinterpret.py: 134: AssertionError ============== ============== 1 failed in 0.55 seconds ================== ==========

+4
source share
2 answers

Pytest has a workaround for jython without an AST implementation, see issue1479 . I just extended the pytest side workaround to work on jython-2.5.3. You can install the pytest dev candidate with:

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

and should get at least version 2.3.4.dev1 with "py.test-jython --version" and get statements working with jython-2.5.3.

+3
source

Currently pytest does not support Jython2.5.3, only works on Jython2.5.1.

+2
source

Source: https://habr.com/ru/post/1444333/


All Articles