question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

suggestion: improve raises confusing message when matching

See original GitHub issue
  • 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)'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
bluetechcommented, Jul 13, 2020

One alternative is to use or to regex match and perform string comparison

I don’t think this is a good idea, because I may want to pass an actual regex which happens to be string-equal but not regex-match.

I think we can improve in these ways:

  1. If string-equal, but not regex-match, show a “Did you mean” help message (as suggested by @RonnyPfannschmidt).
  2. Change “Pattern …” to “Regex pattern …” (as suggested by @asottile).
  3. Prefix r to the regex pattern, as another visual indicator that it’s a regex. (It would need to actually be valid of course).

WDYT?

2reactions
RonnyPfannschmidtcommented, Jul 13, 2020

A check for exact equality + a value error on forgotten regex escape may prevent some headscratching

Read more comments on GitHub >

github_iconTop Results From Across the Web

When and How Do Message Matching Interventions Work?
we can compare different procedures that have been used in research to increase the specificity with which messages are made to match people's ......
Read more >
Effective Communication - HelpGuide.org
Want to communicate better? These tips will help you get your message across, avoid misunderstandings, and improve your relationships.
Read more >
10 Usability Heuristics for User Interface Design
10 Usability Heuristics for User Interface Design · #1: Visibility of system status · #2: Match between system and the real world ·...
Read more >
Match.com Profile, Bio, Question, Answer Guide, Cost, Photos
Biggest Mistakes Made On Match.com Profiles, Bios, Photos ... wait to collect messages, likes, improved photos/profiles before deciding to ...
Read more >
Issues - SonarQube Documentation
While running an analysis, SonarQube raises an issue every time a piece of code ... and on the same rule (but not necessarily...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found