diff --git a/django_expanded_test_cases/mixins/response_mixin.py b/django_expanded_test_cases/mixins/response_mixin.py index 7a41d1257942eed09829dc1dcc4c0d979e441d02..e472047876083974159a8a9396b63bd6eb14c3fd 100644 --- a/django_expanded_test_cases/mixins/response_mixin.py +++ b/django_expanded_test_cases/mixins/response_mixin.py @@ -140,17 +140,33 @@ class ResponseTestCaseMixin(CoreTestCaseMixin): # Attempt to access key object. If fails, attempt to generate dict of values. try: response_context.keys() + except AttributeError: # Handling for: # * django.template.context.RequestContext # * django.template.context.Context - # No guarantee this will work for other aribtrary types. + # No guarantee this will work for other arbitrary types. # Handle as they come up. temp_dict = {} for context in response_context: temp_dict = {**temp_dict, **context} response_context = temp_dict + except Exception as err: + # Error occurred. + # Check if error is due to ContextDict/ContextList object being passed. + # Unsure why this happens, but seems to occur in tests that access Django 4.2.7 admin views? + # Needs further research. For now, this seems like enough to bypass it + # and have no immediately noticeable side effects. + from django.test.utils import ContextList + if isinstance(response_context, ContextList): + # Skip output. + return + + else: + # Raise original error. + raise err + self._debug_print() self._debug_print( '{0} {1} {0}'.format('=' * 10, 'response.context'),