Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add self.assertRaisesWithMessageContaining() to TestBase and use it to clean up #7303

@@ -8,7 +8,7 @@
import logging
import os
import unittest
from builtins import object, open
from builtins import object, open, str
from collections import defaultdict
from contextlib import contextmanager
from tempfile import mkdtemp
@@ -616,6 +616,23 @@ def assertInFile(self, string, file_path):
content =
self.assertIn(string, content, '"{}" is not in the file {}:\n{}'.format(string,, content))

def assertRaisesWithMessageContaining(self, exception_type, error_text, substring_match=False):

This comment has been minimized.

Copy link

Eric-Arellano Mar 3, 2019


Hm, this new parameter name isn't immediately clear to me what it means. I strongly prefer exact=True, followed by inexact=False instead. If those sound off, maybe exact_message_match or a variant.

I think substring is throwing me off because I always associate a substring with grabbing a specific index from the bigger string and then checking if that specific substring is present.


Thanks for changing the default behavior!

This comment has been minimized.

Copy link

cosmicexplorer Mar 3, 2019

Author Contributor

My concern was that exact may connote that the alternative is some sort of fuzzy matching. I was also thinking of only_contains. I'll push a commit using exact=True and see what that looks like.

"""Verifies that a string appears in an exception message.
:param type exception_type: The exception type which is expected to be raised within the body.
:param str error_text: Text that the exception message should either contain or match exactly.
:param bool substring_match: If True, use `self.assertIn()` instead of `self.assertEqual()` to
match the exception text.
:API: public
with self.assertRaises(exception_type) as cm:
yield cm
if substring_match:
self.assertIn(error_text, str(cm.exception))
self.assertEqual(error_text, str(cm.exception))

def get_bootstrap_options(self, cli_options=()):
"""Retrieves bootstrap options.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.