Index: urllib3-1.5/test/test_collections.py =================================================================== --- urllib3-1.5.orig/test/test_collections.py +++ urllib3-1.5/test/test_collections.py @@ -122,9 +122,11 @@ class TestLRUContainer(unittest.TestCase def test_iter(self): d = Container() - with self.assertRaises(NotImplementedError): + def to_test(): for i in d: self.fail("Iteration shouldn't be implemented.") + self.assertRaises(NotImplementedError, to_test) + if __name__ == '__main__': unittest.main() Index: urllib3-1.5/test/test_connectionpool.py =================================================================== --- urllib3-1.5.orig/test/test_connectionpool.py +++ urllib3-1.5/test/test_connectionpool.py @@ -98,8 +98,7 @@ class TestConnectionPool(unittest.TestCa def _test(exception, expect): pool._make_request = lambda *args, **kwargs: _raise(exception) - with self.assertRaises(expect): - pool.request('GET', '/') + self.assertRaises(expect, pool.request, 'GET', '/') self.assertEqual(pool.pool.qsize(), POOL_SIZE) @@ -114,15 +113,13 @@ class TestConnectionPool(unittest.TestCa # MaxRetryError, not EmptyPoolError # See: https://github.com/shazow/urllib3/issues/76 pool._make_request = lambda *args, **kwargs: _raise(HTTPException) - with self.assertRaises(MaxRetryError): - pool.request('GET', '/', retries=1, pool_timeout=0.01) + self.assertRaises(MaxRetryError, pool.request, 'GET', '/', retries=1, pool_timeout=0.01) self.assertEqual(pool.pool.qsize(), POOL_SIZE) def test_assert_same_host(self): c = connection_from_url('http://google.com:80') - with self.assertRaises(HostChangedError): - c.request('GET', 'http://yahoo.com:80', assert_same_host=True) + self.assertRaises(HostChangedError, c.request, 'GET', 'http://yahoo.com:80', assert_same_host=True) def test_pool_close(self): pool = connection_from_url('http://google.com:80') @@ -139,16 +136,13 @@ class TestConnectionPool(unittest.TestCa pool.close() self.assertEqual(pool.pool, None) - with self.assertRaises(ClosedPoolError): - pool._get_conn() + self.assertRaises(ClosedPoolError, pool._get_conn) pool._put_conn(conn3) - with self.assertRaises(ClosedPoolError): - pool._get_conn() + self.assertRaises(ClosedPoolError, pool._get_conn) - with self.assertRaises(Empty): - old_pool_queue.get(block=False) + self.assertRaises(Empty, old_pool_queue.get, block=False) if __name__ == '__main__': Index: urllib3-1.5/test/test_poolmanager.py =================================================================== --- urllib3-1.5.orig/test/test_poolmanager.py +++ urllib3-1.5/test/test_poolmanager.py @@ -54,13 +54,11 @@ class TestPoolManager(unittest.TestCase) p.clear() self.assertEqual(len(p.pools), 0) - with self.assertRaises(ClosedPoolError): - conn_pool._get_conn() + self.assertRaises(ClosedPoolError, conn_pool._get_conn) conn_pool._put_conn(conn) - with self.assertRaises(ClosedPoolError): - conn_pool._get_conn() + self.assertRaises(ClosedPoolError, conn_pool._get_conn) self.assertEqual(len(p.pools), 0)