File: test_queue_monkeypatch.py

package info (click to toggle)
python-urllib3 1.26.5-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,260 kB
  • sloc: python: 16,933; makefile: 130
file content (30 lines) | stat: -rw-r--r-- 775 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import absolute_import

import mock
import pytest

from urllib3 import HTTPConnectionPool
from urllib3.exceptions import EmptyPoolError
from six.moves import queue


class BadError(Exception):
    """
    This should not be raised.
    """

    pass


class TestMonkeypatchResistance(object):
    """
    Test that connection pool works even with a monkey patched Queue module,
    see obspy/obspy#1599, psf/requests#3742, urllib3/urllib3#1061.
    """

    def test_queue_monkeypatching(self):
        with mock.patch.object(queue, "Empty", BadError):
            with HTTPConnectionPool(host="localhost", block=True) as http:
                http._get_conn()
                with pytest.raises(EmptyPoolError):
                    http._get_conn(timeout=0)