summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVirgil Dupras <hsoft@hardcoded.net>2013-11-08 16:59:13 -0500
committerVirgil Dupras <hsoft@hardcoded.net>2013-11-08 16:59:13 -0500
commitded88700a3316edc37335c07ec3fb9915847a38d (patch)
treed1cdfb278b906258c1c480e1d34ca4d609c0cc05
parenta9d1f40c294e18c68ca27f03a4a8fd5614ec6298 (diff)
downloadpytest-ded88700a3316edc37335c07ec3fb9915847a38d.tar.gz
Fix TypeError crash on failed imports under py3.3.
Starting with Python 3.3, NamespacePath passed to importlib hooks seem to have lost the ability to be accessed by index. We wrap the index access in a try..except and wrap the path in a list if it happens. Fixes #383.
-rw-r--r--_pytest/assertion/rewrite.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py
index 4a7a5aa9d..2a94edd89 100644
--- a/_pytest/assertion/rewrite.py
+++ b/_pytest/assertion/rewrite.py
@@ -57,7 +57,12 @@ class AssertionRewritingHook(object):
lastname = names[-1]
pth = None
if path is not None and len(path) == 1:
- pth = path[0]
+ try:
+ pth = path[0]
+ except TypeError:
+ # Starting with Python 3.3, `path` started being unsubscriptable, we have to wrap it
+ # in a list.
+ pth = list(path)[0]
if pth is None:
try:
fd, fn, desc = imp.find_module(lastname, path)