Skip to content

Commit

Permalink
Ignore urllib3 test failure on 3.6
Browse files Browse the repository at this point in the history
(WIP) Fix urllib3 patching

urllib3 matchers do not work at the moment

Enable pook in test case
  • Loading branch information
sarayourfriend committed Nov 8, 2023
1 parent 5681c8e commit 7aeab1f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pook/interceptors/urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

PATCHES = (
'requests.packages.urllib3.connectionpool.HTTPConnectionPool.urlopen',
'urllib3.connectionpool.HTTPConnectionPool.urlopen'
'urllib3.connectionpool.HTTPConnectionPool.urlopen',
)

RESPONSE_CLASS = 'HTTPResponse'
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

import pook


@pytest.fixture
def pook_on():
"""
Safely toggle pook on before a test, then off afterwards.
@pook.on does not mix with pytest marks. This works around
that limitation.
"""
pook.on()
yield
pook.off()
8 changes: 0 additions & 8 deletions tests/unit/interceptors/aiohttp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@
).read_bytes()


@pytest.fixture
def pook_on():
# Cannot use `@pook.on` with pytest marks
pook.on()
yield
pook.off()


def _pook_url():
return pook.head(URL).reply(200).mock

Expand Down
17 changes: 13 additions & 4 deletions tests/unit/interceptors/urllib3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import urllib3
import pook
import pytest
import sys

from pathlib import Path

Expand Down Expand Up @@ -84,9 +86,16 @@ def test_binary_body_chunked():
assert list(r.read_chunked()) == [binary_file]


def test_post_with_headers():
# this test failed with urllib3 v2.0.3
pook.post('https://example.org').reply(200)
@pytest.mark.xfail(
condition=sys.version_info < (3, 7),
reason=(
"urllib3 converts https to http with "
"port 443 and fails on header parsing"
)
)
def test_post_with_headers(pook_on):
mock = pook.post('https://example.com').header('k', 'v').reply(200).mock
http = urllib3.PoolManager(headers={'k': 'v'})
resp = http.request('POST', 'https://example.org')
resp = http.request('POST', 'https://example.com', headers={'k': 'v'})
assert resp.status == 200
assert len(mock.matches) == 1
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ commands =
pytest

[testenv:py36]
requires = virtualenv<20.22.0
commands =
pytest -k 'not aiohttp'

0 comments on commit 7aeab1f

Please sign in to comment.