diff --git a/CHANGELOG b/CHANGELOG index 9662f12ee..e56357834 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ Changes between 1.3.2 and 1.3.3a1 ================================================== +- fix issue113: assertion representation problem with triple-quoted strings + (and possibly other cases) - make conftest loading detect that a conftest file with the same content was already loaded, avoids surprises in nested directory structures that can be produced e.g. by Hudson. It alleviates the need to use diff --git a/py/_code/source.py b/py/_code/source.py index 0f47d3d8d..52ab252a0 100644 --- a/py/_code/source.py +++ b/py/_code/source.py @@ -125,16 +125,13 @@ class Source(object): try: compile_command(trysource) except (SyntaxError, OverflowError, ValueError): - pass - else: - break # got a valid or incomplete statement - - # 2. find the end of the statement - for end in range(lineno+1, len(self)+1): - trysource = self[start:end] - if trysource.isparseable(): - break + continue + # 2. find the end of the statement + for end in range(lineno+1, len(self)+1): + trysource = self[start:end] + if trysource.isparseable(): + return start, end return start, end def getblockend(self, lineno): diff --git a/testing/code/test_source.py b/testing/code/test_source.py index ef651c363..4be583803 100644 --- a/testing/code/test_source.py +++ b/testing/code/test_source.py @@ -176,6 +176,13 @@ class TestSourceParsingAndCompiling: #x = s.deindent() assert str(s) == ass + def test_getstatementrange_triple_quoted(self): + #print str(self.source) + source = Source("""''' + '''""") + s = source.getstatement(1) + assert eval(str(s)) + def test_getstatementrange_within_constructs(self): source = Source("""\ try: diff --git a/testing/plugin/test_pytest_assertion.py b/testing/plugin/test_pytest_assertion.py index 75236658b..c76a93b4d 100644 --- a/testing/plugin/test_pytest_assertion.py +++ b/testing/plugin/test_pytest_assertion.py @@ -9,6 +9,17 @@ def test_functional(testdir): result = testdir.runpytest("--no-assert") assert "3 == 4" not in result.stdout.str() +def test_triple_quoted_string_issue113(testdir): + testdir.makepyfile(""" + def test_hello(): + assert "" == ''' + '''""") + result = testdir.runpytest("--fulltrace") + result.stdout.fnmatch_lines([ + "*1 failed*", + ]) + assert 'SyntaxError' not in result.stdout.str() + def test_traceback_failure(testdir): p1 = testdir.makepyfile(""" def g():