diff --git a/django_expanded_test_cases/constants.py b/django_expanded_test_cases/constants.py index f5664aa6e95cb1742f503475aab9beca6c0d3e6a..c3b79523a5c0526c068dd7bfafe8e62f5917327a 100644 --- a/django_expanded_test_cases/constants.py +++ b/django_expanded_test_cases/constants.py @@ -180,6 +180,14 @@ ETC_DEBUG_PRINT = bool(getattr( 'DJANGO_EXPANDED_TESTCASES_DEBUG_PRINT', True, )) +# A set of regex-matching strings to skip displaying during debug output. +# Useful such as when importing third-party libraries with front-end elements, if you don't expect to ever +# need to test for said elements. +ETC_DEBUG_PRINT__SKIP_DISPLAY = getattr( + settings, + 'DJANGO_EXPANDED_TESTCASES_DEBUG_PRINT__SKIP_DISPLAY', + [], +) # Indicates whether partial matches are allowed for site title assertions. # IE: Will pass as long as provided text appears as a subsection of the full site title. # Defaults to needing exact match. diff --git a/django_expanded_test_cases/mixins/response_mixin.py b/django_expanded_test_cases/mixins/response_mixin.py index 97377f2d230ecd0df3fd798623809ac068a5804c..7a41d1257942eed09829dc1dcc4c0d979e441d02 100644 --- a/django_expanded_test_cases/mixins/response_mixin.py +++ b/django_expanded_test_cases/mixins/response_mixin.py @@ -28,6 +28,7 @@ from django_expanded_test_cases.constants import ( ETC_RESPONSE_DEBUG_USER_INFO_COLOR, ETC_OUTPUT_EMPHASIS_COLOR, ETC_AUTO_GENERATE_USERS, + ETC_DEBUG_PRINT__SKIP_DISPLAY ) @@ -84,6 +85,17 @@ class ResponseTestCaseMixin(CoreTestCaseMixin): # Print out data, if present. if response_content: + + # Attempt to remove all regex matches from content to display. + for match_attempt in ETC_DEBUG_PRINT__SKIP_DISPLAY: + + # For each string, modify to match output formatting and convert to regex. + match_attempt = r'{0}'.format(self.get_minimized_response_content(match_attempt)) + + # Attempt to do content strip. + response_content = re.sub(match_attempt, '', response_content) + + # Display content to console (only shows up on test error). self._debug_print(response_content) self._debug_print()