Merged in hsoft/pytest (pull request #81)
Fix TypeError crash on failed imports under py3.3.
This commit is contained in:
		
						commit
						581b3a110c
					
				| 
						 | 
				
			
			@ -56,8 +56,12 @@ class AssertionRewritingHook(object):
 | 
			
		|||
        names = name.rsplit(".", 1)
 | 
			
		||||
        lastname = names[-1]
 | 
			
		||||
        pth = None
 | 
			
		||||
        if path is not None and len(path) == 1:
 | 
			
		||||
            pth = path[0]
 | 
			
		||||
        if path is not None:
 | 
			
		||||
            # Starting with Python 3.3, path is a _NamespacePath(), which
 | 
			
		||||
            # causes problems if not converted to list.
 | 
			
		||||
            path = list(path)
 | 
			
		||||
            if len(path) == 1:
 | 
			
		||||
                pth = path[0]
 | 
			
		||||
        if pth is None:
 | 
			
		||||
            try:
 | 
			
		||||
                fd, fn, desc = imp.find_module(lastname, path)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -308,6 +308,24 @@ class TestGeneralUsage:
 | 
			
		|||
            ])
 | 
			
		||||
            assert result.ret == 4  # usage error only if item not found
 | 
			
		||||
    
 | 
			
		||||
    def test_namespace_import_doesnt_confuse_import_hook(self, testdir):
 | 
			
		||||
        # Ref #383. Python 3.3's namespace package messed with our import hooks
 | 
			
		||||
        # Importing a module that didn't exist, even if the ImportError was
 | 
			
		||||
        # gracefully handled, would make our test crash.
 | 
			
		||||
        testdir.mkdir('not_a_package')
 | 
			
		||||
        p = testdir.makepyfile("""
 | 
			
		||||
            try:
 | 
			
		||||
                from not_a_package import doesnt_exist
 | 
			
		||||
            except ImportError:
 | 
			
		||||
                # We handle the import error gracefully here
 | 
			
		||||
                pass
 | 
			
		||||
            
 | 
			
		||||
            def test_whatever():
 | 
			
		||||
                pass
 | 
			
		||||
        """)
 | 
			
		||||
        res = testdir.runpytest(p.basename)
 | 
			
		||||
        assert res.ret == 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestInvocationVariants:
 | 
			
		||||
    def test_earlyinit(self, testdir):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue