pytest-dev / py

Python development support library (note: maintenance only)
MIT License
69 stars 105 forks source link

broken comment parsing #55

Closed pytestbot closed 8 years ago

pytestbot commented 8 years ago

see https://bitbucket.org/hpk42/pytest/issue/563/unrelated-multiline-comments-shown-in for details

pytestbot commented 8 years ago

Original comment by @oxyum

@hannes_ucsc "--tb=native" should help.

pytestbot commented 8 years ago

Original comment by @hannes-ucsc

Is there a way to disable this whole feature in case the heuristic fails?

pytestbot commented 8 years ago

Original comment by @hpk42

fix issue55: refine (still somewhat) heuristic algorithm for identifying the lines that belong to a statement

→ <<cset 7fba3887a4e0>>

pytestbot commented 8 years ago

Original comment by @blueyed

Here is a test that is currently failing, too:

diff -r d7d5337ac74a testing/code/test_source.py
--- a/testing/code/test_source.py       Sat Dec 27 01:47:36 2014 +0100
+++ b/testing/code/test_source.py       Thu May 28 17:37:11 2015 +0200
@@ -508,6 +508,14 @@
         assert str(getstatement(line, source)) == '    assert False'
     assert str(getstatement(10, source)) == '"""'

+def test_comment_in_statement():
+    source = '''test(foo=1,
+    # comment 1
+    bar=2)
+'''
+    for line in range(1,3):
+        assert str(getstatement(line, source)) == 'test(foo=1,\n    bar=2)'
+
 def test_single_line_else():
     source = getstatement(1, "if False: 2\nelse: 3")
     assert str(source) == "else: 3"
pytestbot commented 8 years ago

Original comment by @ttanner

yes, that's why I reopened it

pytestbot commented 8 years ago

Original comment by @hpk42

right -- so it's related to your own PR? :)

pytestbot commented 8 years ago

Original comment by @ttanner

please try HEAD (1.4.27-dev), not 1.4.26 :)

pytestbot commented 8 years ago

Original comment by @hpk42

For me it works:

#!python

================================== test session starts ==================================
platform linux2 -- Python 2.7.6 -- py-1.4.26 -- pytest-2.7.1.dev
rootdir: /home/hpk/p/devpi/server, inifile: tox.ini
plugins: cache, xdist, flakes, capturelog, timeout, cov, pep8
collected 1 items 

x.py F

======================================= FAILURES ========================================
_________________________________________ test __________________________________________

    def test():
        [
>   'valid', bad]
E       NameError: global name 'bad' is not defined

x.py:4: NameError
================================ short test summary info ================================
FAIL x.py::test

my file contains:


def test():
    [
'valid', bad]
pytestbot commented 8 years ago

Original comment by @ttanner

unfortunately, this heuristic turns out to broken,too. It seems we need more sophisticated source parsing to get it right.

#!python

def test():
    [
'valid',bad]

crashes with:

#!

============================= test session starts ==============================
platform darwin -- Python 2.7.9 -- py-1.4.27.dev1 -- pytest-2.6.4
plugins: pythonpath
collected 1 items

test_bug.py 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File ".../_pytest/main.py", line 84, in wrap_session
INTERNALERROR>     doit(config, session)
INTERNALERROR>   File ".../_pytest/main.py", line 122, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File ".../_pytest/core.py", line 413, in __call__
INTERNALERROR>     return self._docall(methods, kwargs)
INTERNALERROR>   File ".../_pytest/core.py", line 424, in _docall
INTERNALERROR>     res = mc.execute()
INTERNALERROR>   File ".../_pytest/core.py", line 315, in execute
INTERNALERROR>     res = method(**kwargs)
INTERNALERROR>   File ".../_pytest/main.py", line 142, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File ".../_pytest/core.py", line 413, in __call__
INTERNALERROR>     return self._docall(methods, kwargs)
INTERNALERROR>   File ".../_pytest/core.py", line 424, in _docall
INTERNALERROR>     res = mc.execute()
INTERNALERROR>   File ".../_pytest/core.py", line 315, in execute
INTERNALERROR>     res = method(**kwargs)
INTERNALERROR>   File ".../_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File ".../_pytest/runner.py", line 75, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File ".../_pytest/runner.py", line 111, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File ".../_pytest/main.py", line 167, in call_matching_hooks
INTERNALERROR>     return hookmethod.pcall(plugins, **kwargs)
INTERNALERROR>   File ".../_pytest/core.py", line 417, in pcall
INTERNALERROR>     return self._docall(methods, kwargs)
INTERNALERROR>   File ".../_pytest/core.py", line 424, in _docall
INTERNALERROR>     res = mc.execute()
INTERNALERROR>   File ".../_pytest/core.py", line 315, in execute
INTERNALERROR>     res = method(**kwargs)
INTERNALERROR>   File ".../_pytest/runner.py", line 214, in pytest_runtest_makereport
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File ".../_pytest/python.py", line 600, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File ".../_pytest/python.py", line 593, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File ".../_pytest/main.py", line 412, in _repr_failure_py
INTERNALERROR>     style=style, tbfilter=tbfilter)
INTERNALERROR>   File ".../py/_code/code.py", line 412, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File ".../py/_code/code.py", line 590, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR>   File ".../py/_code/code.py", line 582, in repr_traceback
INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR>   File ".../py/_code/code.py", line 543, in repr_traceback_entry
INTERNALERROR>     s = self.get_source(source, line_index, excinfo, short=short)
INTERNALERROR>   File ".../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

===============================  in 0.39 seconds ===============================
pytestbot commented 8 years ago

Original comment by @ttanner

merged https://bitbucket.org/pytest-dev/py/pull-request/23/fix-for-55/diff