[Pytest-commit] commit/pytest: hpk42: Merged in getsourcelines-error-issue-553-pytest2.7 (pull request #273)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Apr 17 22:32:04 CEST 2015
1 new commit in pytest:
https://bitbucket.org/pytest-dev/pytest/commits/a7d1219faa25/
Changeset: a7d1219faa25
Branch: pytest-2.7
User: hpk42
Date: 2015-04-17 20:31:55+00:00
Summary: Merged in getsourcelines-error-issue-553-pytest2.7 (pull request #273)
Handle inspect.getsourcelines failures in FixtureLookupError
Affected #: 3 files
diff -r f61e0f6a9f49f12278020f2007a1931e01821df3 -r a7d1219faa250eef78d6c2ced47f2199ca01f7e1 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff -r f61e0f6a9f49f12278020f2007a1931e01821df3 -r a7d1219faa250eef78d6c2ced47f2199ca01f7e1 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1537,13 +1537,18 @@
# it at the requesting side
for function in stack:
fspath, lineno = getfslineno(function)
- lines, _ = inspect.getsourcelines(function)
- addline("file %s, line %s" % (fspath, lineno+1))
- for i, line in enumerate(lines):
- line = line.rstrip()
- addline(" " + line)
- if line.lstrip().startswith('def'):
- break
+ 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()
+ addline(" " + line)
+ if line.lstrip().startswith('def'):
+ break
if msg is None:
fm = self.request._fixturemanager
diff -r f61e0f6a9f49f12278020f2007a1931e01821df3 -r a7d1219faa250eef78d6c2ced47f2199ca01f7e1 testing/acceptance_test.py
--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -353,6 +353,23 @@
*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):
Repository URL: https://bitbucket.org/pytest-dev/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list