pytest: suggestion: improve raises confusing message when matching
-
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)'
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- Change Exception message See #7489 — committed to Techlete/pytest by Lewiscowles1986 4 years ago
- Change Exception message See #7489 — committed to Techlete/pytest by Lewiscowles1986 4 years ago
- Change Exception message See #7489 — committed to Techlete/pytest by Lewiscowles1986 4 years ago
- Merge #6 #7 6: Pin pytest to latest version 6.2.3 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.3**. <details> <summary>Changelog</su... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #6 6: Pin pytest to latest version 6.2.3 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.3**. <details> <summary>Changelog</summa... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #3 #4 3: Pin sphinx_rtd_theme to latest version 0.5.1 r=aragilar a=pyup-bot This PR pins [sphinx_rtd_theme](https://pypi.org/project/sphinx_rtd_theme) to the latest release **0.5.1**. *The... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #7 #8 7: Pin sphinx_rtd_theme to latest version 0.5.2 r=aragilar a=pyup-bot This PR pins [sphinx_rtd_theme](https://pypi.org/project/sphinx_rtd_theme) to the latest release **0.5.2**. *The... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #4 4: Pin pytest to latest version 6.2.2 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.2**. <details> <summary>Changelog</summa... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #18 #20 18: Pin pytest to latest version 6.2.4 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.4**. <details> <summary>Changelog<... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #16 16: Pin pytest to latest version 6.2.4 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.4**. <details> <summary>Changelog</sum... — committed to aragilar/venv_tools by bors[bot] 3 years ago
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:
r
to the regex pattern, as another visual indicator that it’s a regex. (It would need to actually be valid of course).WDYT?
A check for exact equality + a value error on forgotten regex escape may prevent some headscratching
@Lewiscowles1986 I wasn’t replying to you, sorry if the quote wasn’t clear
@Lewiscowles1986, yes, the check is done here:
https://github.com/pytest-dev/pytest/blob/7f7a36478abe7dd1fa993b115d22606aa0e35e88/src/_pytest/_code/code.py#L605-L616