Skip to content

Commit 587d48a

Browse files
committed
Fix JSONReponse.__eq__ on Python2 😓
1 parent df6d7be commit 587d48a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pytest_flask/plugin.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
:copyright: (c) by Vital Kudzelka
77
:license: MIT
88
"""
9+
import sys
10+
911
import pytest
1012

1113
from flask import json
@@ -32,7 +34,17 @@ def json(self):
3234
def __eq__(self, other):
3335
if isinstance(other, int):
3436
return self.status_code == other
35-
return super(JSONResponse, self).__eq__(other)
37+
# even though the Python 2-specific code works on Python 3, keep the two versions
38+
# separate so we can simplify the code once Python 2 support is dropped
39+
if sys.version_info[0] == 2:
40+
try:
41+
super_eq = super(JSONResponse, self).__eq__
42+
except AttributeError:
43+
return NotImplemented
44+
else:
45+
return super_eq(other)
46+
else:
47+
return super(JSONResponse, self).__eq__(other)
3648

3749
def __ne__(self, other):
3850
return not self == other

0 commit comments

Comments
 (0)