Skip to content

Commit 7ab3823

Browse files
jacepgjones
authored andcommitted
Fix: Use issubclass instead of isinstance
Bug described at #2831
1 parent 4e5bdca commit 7ab3823

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/werkzeug/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,12 @@ def __init__(
809809

810810
if response_wrapper in {None, Response}:
811811
response_wrapper = TestResponse
812-
elif not isinstance(response_wrapper, TestResponse):
812+
elif response_wrapper is not None and not issubclass(
813+
response_wrapper, TestResponse
814+
):
813815
response_wrapper = type(
814816
"WrapperTestResponse",
815-
(TestResponse, response_wrapper), # type: ignore
817+
(TestResponse, response_wrapper),
816818
{},
817819
)
818820

tests/test_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from werkzeug.test import EnvironBuilder
1717
from werkzeug.test import run_wsgi_app
1818
from werkzeug.test import stream_encode_multipart
19+
from werkzeug.test import TestResponse
1920
from werkzeug.utils import redirect
2021
from werkzeug.wrappers import Request
2122
from werkzeug.wrappers import Response
@@ -903,3 +904,24 @@ def test_no_content_type_header_addition():
903904
c = Client(no_response_headers_app)
904905
response = c.open()
905906
assert response.headers == Headers([("Content-Length", "8")])
907+
908+
909+
def test_client_response_wrapper():
910+
class CustomResponse(Response):
911+
pass
912+
913+
class CustomTestResponse(TestResponse, Response):
914+
pass
915+
916+
c1 = Client(Response(), CustomResponse)
917+
r1 = c1.open()
918+
919+
assert isinstance(r1, CustomResponse)
920+
assert type(r1) is not CustomResponse # Got subclassed
921+
assert issubclass(type(r1), CustomResponse)
922+
923+
c2 = Client(Response(), CustomTestResponse)
924+
r2 = c2.open()
925+
926+
assert isinstance(r2, CustomTestResponse)
927+
assert type(r2) is CustomTestResponse # Did not get subclassed

0 commit comments

Comments
 (0)