[Pytest-commit] Issue #739: triple quotes can mess up source code parsing (pytest-dev/pytest)
Tomi Pieviläinen
issues-reply at bitbucket.org
Fri May 8 07:01:56 CEST 2015
New issue 739: triple quotes can mess up source code parsing
https://bitbucket.org/pytest-dev/pytest/issue/739/triple-quotes-can-mess-up-source-code
Tomi Pieviläinen:
There seems to be a weird corner case with triple quotes. With a test file
def test_1_works():
('''
''').doesnt_exist()
def test_2_works():
('''
''').lower()
def test_3_works():
'''
'''.doesnt_exist()
def test_1_fails():
('''
''').doesnt_exist()
def test_2_fails():
('''
''').doesnt_exist()
py.test crashes with INTERNALERROR:
$ py.test
============================================================================ test session starts ============================================================================
platform linux -- Python 3.4.3 -- py-1.4.27 -- pytest-2.7.0
rootdir: /home/hukka/pytest-test, inifile:
collected 5 items
test_pytest.py F.F
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/main.py", line 84, in wrap_session
INTERNALERROR> doit(config, session)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/main.py", line 122, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR> return self._docall(self.methods, kwargs)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR> firstresult=self.firstresult).execute()
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR> res = method(*args)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/main.py", line 142, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR> return self._docall(self.methods, kwargs)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR> firstresult=self.firstresult).execute()
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 393, in execute
INTERNALERROR> return wrapped_call(method(*args), self.execute)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 113, in wrapped_call
INTERNALERROR> return call_outcome.get_result()
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 137, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 123, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR> res = method(*args)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/runner.py", line 75, in runtestprotocol
INTERNALERROR> reports.append(call_and_report(item, "call", log))
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR> report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR> return self._docall(self.methods, kwargs)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR> firstresult=self.firstresult).execute()
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 393, in execute
INTERNALERROR> return wrapped_call(method(*args), self.execute)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 109, in wrapped_call
INTERNALERROR> wrap_controller.send(call_outcome)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/skipping.py", line 157, in pytest_runtest_makereport
INTERNALERROR> rep = outcome.get_result()
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 137, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 123, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR> res = method(*args)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/runner.py", line 224, in pytest_runtest_makereport
INTERNALERROR> longrepr = item.repr_failure(excinfo)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/python.py", line 625, in repr_failure
INTERNALERROR> return self._repr_failure_py(excinfo, style=style)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/python.py", line 618, in _repr_failure_py
INTERNALERROR> style=style)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/_pytest/main.py", line 410, in _repr_failure_py
INTERNALERROR> style=style, tbfilter=tbfilter)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/py/_code/code.py", line 412, in getrepr
INTERNALERROR> return fmt.repr_excinfo(self)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/py/_code/code.py", line 590, in repr_excinfo
INTERNALERROR> reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/py/_code/code.py", line 582, in repr_traceback
INTERNALERROR> reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/py/_code/code.py", line 543, in repr_traceback_entry
INTERNALERROR> s = self.get_source(source, line_index, excinfo, short=short)
INTERNALERROR> File "/home/hukka/addressimport/lib/python3.4/site-packages/py/_code/code.py", line 484, in get_source
INTERNALERROR> lines.append(self.flow_marker + " " + source.lines[line_index])
INTERNALERROR> IndexError: list index out of range
==================================================================== 2 failed, 1 passed in 0.03 seconds ====================================================================
The first three tests work fine on their own:
$ py.test
============================================================================ test session starts ============================================================================
platform linux -- Python 3.4.3 -- py-1.4.27 -- pytest-2.7.0
rootdir: /home/hukka/pytest-test, inifile:
collected 3 items
test_pytest.py F.F
================================================================================= FAILURES ==================================================================================
_______________________________________________________________________________ test_1_works ________________________________________________________________________________
def test_1_works():
('''
> ''').doesnt_exist()
E AttributeError: 'str' object has no attribute 'doesnt_exist'
test_pytest.py:3: AttributeError
_______________________________________________________________________________ test_3_works ________________________________________________________________________________
def test_3_works():
'''
> '''.doesnt_exist()
E AttributeError: 'str' object has no attribute 'doesnt_exist'
test_pytest.py:13: AttributeError
==================================================================== 2 failed, 1 passed in 0.02 seconds ====================================================================
but either of the last two will cause this. Same thing happens also on python2.7.
More information about the pytest-commit
mailing list