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, exact=False):
This conversation was marked as resolved by cosmicexplorer

This comment has been minimized.

Copy link

Eric-Arellano Mar 2, 2019


I think we want to default to exact=True. Seems better to default to the most secure/sane possible, and have to intentionally opt in to a less strong expectation.

I love that this is an option!

This comment has been minimized.

Copy link

cosmicexplorer Mar 2, 2019

Author Contributor

I agree, will make this change (might change the name of the arg to something like inexact or substring_match).

This comment has been minimized.

Copy link

cosmicexplorer Mar 3, 2019

Author Contributor

Changed to substring_match=False!

"""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 exact: If True, use `self.assertEqual()` instead of `self.assertIn()` to match the
exception text. This provides a stronger guarantee but may not be necessary.
:API: public
with self.assertRaises(exception_type) as cm:
yield cm
if exact:
self.assertEqual(error_text, str(cm.exception))
self.assertIn(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.