fix Issue 274 - dont fail when doctest does not know the example location
instead only the last test is shown, this could use some further enhancement
This commit is contained in:
		
							parent
							
								
									5e479c94ce
								
							
						
					
					
						commit
						93da606763
					
				|  | @ -1,6 +1,9 @@ | |||
| Changes between 2.3.4 and 2.3.5dev | ||||
| ----------------------------------- | ||||
| 
 | ||||
| - Issue 274 - dont try to show full doctest example | ||||
|   when doctest does not know the example location | ||||
| 
 | ||||
| - issue 280 - disable assertion rewriting on buggy CPython 2.6.0 | ||||
| 
 | ||||
| - inject "getfixture()" helper to retrieve fixtures from doctests, | ||||
|  |  | |||
|  | @ -42,17 +42,27 @@ class DoctestItem(pytest.Item): | |||
|             example = doctestfailure.example | ||||
|             test = doctestfailure.test | ||||
|             filename = test.filename | ||||
|             if test.lineno is None: | ||||
|                 lineno = None | ||||
|             else: | ||||
|                 lineno = test.lineno + example.lineno + 1 | ||||
|             message = excinfo.type.__name__ | ||||
|             reprlocation = ReprFileLocation(filename, lineno, message) | ||||
|             checker = py.std.doctest.OutputChecker() | ||||
|             REPORT_UDIFF = py.std.doctest.REPORT_UDIFF | ||||
|             filelines = py.path.local(filename).readlines(cr=0) | ||||
|             i = max(test.lineno, max(0, lineno - 10)) # XXX? | ||||
|             lines = [] | ||||
|             if lineno is not None: | ||||
|                 i = max(test.lineno, max(0, lineno - 10)) # XXX? | ||||
|                 for line in filelines[i:lineno]: | ||||
|                     lines.append("%03d %s" % (i+1, line)) | ||||
|                     i += 1 | ||||
|             else: | ||||
|                 lines.append('EXAMPLE LOCATION UNKNOWN, not showing all tests of that example') | ||||
|                 indent = '>>>' | ||||
|                 for line in example.source.splitlines(): | ||||
|                     lines.append('??? %s %s' % (indent, line)) | ||||
|                     indent = '...' | ||||
|             if excinfo.errisinstance(doctest.DocTestFailure): | ||||
|                 lines += checker.output_difference(example, | ||||
|                         doctestfailure.got, REPORT_UDIFF).split("\n") | ||||
|  |  | |||
|  | @ -59,6 +59,26 @@ class TestDoctests: | |||
|             "*UNEXPECTED*ZeroDivision*", | ||||
|         ]) | ||||
| 
 | ||||
|     def test_doctest_linedata_missing(self, testdir): | ||||
|         testdir.tmpdir.join('hello.py').write(py.code.Source(""" | ||||
|             class Fun(object): | ||||
|                 @property | ||||
|                 def test(self): | ||||
|                     ''' | ||||
|                     >>> a = 1 | ||||
|                     >>> 1/0 | ||||
|                     ''' | ||||
|             """)) | ||||
|         result = testdir.runpytest("--doctest-modules") | ||||
|         result.stdout.fnmatch_lines([ | ||||
|             "*hello*", | ||||
|             "*EXAMPLE LOCATION UNKNOWN, not showing all tests of that example*", | ||||
|             "*1/0*", | ||||
|             "*UNEXPECTED*ZeroDivision*", | ||||
|             "*1 failed*", | ||||
|         ]) | ||||
| 
 | ||||
| 
 | ||||
|     def test_doctest_unex_importerror(self, testdir): | ||||
|         testdir.tmpdir.join("hello.py").write(py.code.Source(""" | ||||
|             import asdalsdkjaslkdjasd | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue