Merged in getsourcelines-error-issue-553-pytest2.7 (pull request #273)
Handle inspect.getsourcelines failures in FixtureLookupError --HG-- branch : pytest-2.7
This commit is contained in:
		
						commit
						0b361c62c8
					
				|  | @ -1,6 +1,11 @@ | |||
| 2.7.1.dev (compared to 2.7.0) | ||||
| ----------------------------- | ||||
| 
 | ||||
| - fix issue553: properly handling inspect.getsourcelines failures in | ||||
|   FixtureLookupError which would lead to to an internal error, | ||||
|   obfuscating the original problem. Thanks talljosh for initial | ||||
|   diagnose/patch and Bruno Oliveira for final patch. | ||||
| 
 | ||||
| - fix issue660: properly report scope-mismatch-access errors | ||||
|   independently from ordering of fixture arguments.  Also | ||||
|   avoid the pytest internal traceback which does not provide | ||||
|  |  | |||
|  | @ -1537,7 +1537,12 @@ class FixtureLookupError(LookupError): | |||
|                                # it at the requesting side | ||||
|         for function in stack: | ||||
|             fspath, lineno = getfslineno(function) | ||||
|             try: | ||||
|                 lines, _ = inspect.getsourcelines(function) | ||||
|             except IOError: | ||||
|                 error_msg = "file %s, line %s: source code not available" | ||||
|                 addline(error_msg % (fspath, lineno+1)) | ||||
|             else: | ||||
|                 addline("file %s, line %s" % (fspath, lineno+1)) | ||||
|                 for i, line in enumerate(lines): | ||||
|                     line = line.rstrip() | ||||
|  |  | |||
|  | @ -353,6 +353,23 @@ class TestGeneralUsage: | |||
|             *unrecognized* | ||||
|         """) | ||||
| 
 | ||||
|     def test_getsourcelines_error_issue553(self, testdir): | ||||
|         p = testdir.makepyfile(""" | ||||
|             def raise_error(obj): | ||||
|                 raise IOError('source code not available') | ||||
| 
 | ||||
|             import inspect | ||||
|             inspect.getsourcelines = raise_error | ||||
| 
 | ||||
|             def test_foo(invalid_fixture): | ||||
|                 pass | ||||
|         """) | ||||
|         res = testdir.runpytest(p) | ||||
|         res.stdout.fnmatch_lines([ | ||||
|             "*source code not available*", | ||||
|             "*fixture 'invalid_fixture' not found", | ||||
|         ]) | ||||
| 
 | ||||
| 
 | ||||
| class TestInvocationVariants: | ||||
|     def test_earlyinit(self, testdir): | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue