Skip to content

suggestion: improve raises confusing message when matching #7489

@Lewiscowles1986

Description

@Lewiscowles1986
  • a detailed description of the bug or suggestion
    I would like pytest.raises to check if strings have parenthesis in them when match is not None, so that people have that lightbulb moment, rather than head-scratching when it presents two identical strings as not matching.

    E           AssertionError: Pattern 'Length of values (29) does not match length of index (30)' does not match 'Length of values (29) does not match length of index (30)'
  • output of pip list from the virtual environment you are using
    I believe this is not applicable right now. I'm happy to provide one if you believe other modules or libraries are causing this behavior.

  • pytest and operating system versions
    Windows 10 64-bit (I know), all updates installed
    Pytest 5.4.3

  • minimal example if possible edited 22:31 (same day) as the example given was the fixed code including escapes and r prefix

    msg = (
              f"Length of values ({len(newcolumndata)}) "
              f"does not match length of index ({len(data)})"
          )
          with pytest.raises(MismatchedIndexValueError, match=msg):

I believe a more helpful error message

=============================================================================== warnings summary =============================================================================== 
tests/whatever/file.py::test_whatever_function_name_is
  file.py:42: UserWarning: non regex passed to match

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=========================================================================== short test summary info ============================================================================

  E           AssertionError: Pattern 'Length of values (29) does not match length of index (30)' does not match 'Length of values (29) does not match length of index (30)'

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortopic: reportingrelated to terminal output and user-facing messages and errors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions