8000 TestCase.assertRaisesString · Issue #123013 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content < 10000 /span>
TestCase.assertRaisesString #123013
Closed as not planned
Closed as not planned
@dg-pb

Description

@dg-pb

Feature or enhancement

Proposal:

More often I need to check for exact error message and do not need regular expression.

For pure convenience, this would look like.

def assertRaisesString(self, exc, string, *args, **kwargs):
    escaped = re.escape(string)
    return self.assertRaisesRegex(exc, f'^{escaped}$', *args, **kwds)

However, as using regular expression is overkill, could just add pure string case to _AssertRaisesBaseContext:

class _AssertRaisesBaseContext(_BaseTestCaseContext):

    def __init__(self, expected, test_case, expected_string=None, regex=True):
        ...

class _AssertRaisesContext(_AssertRaisesBaseContext):
    def __exit__(self, exc_type, exc_value, tb):
        expected_string = self.expected_string
        exc_string = str(exc_value)
        if self.regex:
            # perform regex
        else:
            # compare strings

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0