1 new commit in pytest:
https://bitbucket.org/pytest-dev/pytest/commits/eb60281e3952/
Changeset: eb60281e3952
User: hpk42
Date: 2015-04-17 20:32:49+00:00
Summary: merge fix of issue553 on pytest-2.7
Affected #: 3 files
diff -r e966701003e436b00e8e517d08d16cb2b1ee9d1c -r
eb60281e3952e5959005669a16c60a9979983de2 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,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 e966701003e436b00e8e517d08d16cb2b1ee9d1c -r
eb60281e3952e5959005669a16c60a9979983de2 _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 e966701003e436b00e8e517d08d16cb2b1ee9d1c -r
eb60281e3952e5959005669a16c60a9979983de2 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.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit