Skip to content

unittest: cannot use bytes regexes - #9107

Merged
hauntsaninja merged 2 commits into
python:mainfrom
JelleZijlstra:unittest
Nov 5, 2022
Merged

unittest: cannot use bytes regexes#9107
hauntsaninja merged 2 commits into
python:mainfrom
JelleZijlstra:unittest

Conversation

@JelleZijlstra

@JelleZijlstraJelleZijlstra commented Nov 5, 2022

Copy link
Copy Markdown
Member
>>> from unittest.case import TestCase
>>> c = TestCase()
>>> with c.assertRaisesRegex(Exception, b"x"): 1/0
...
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/case.py", line 274, in __exit__
if not expected_regex.search(str(exc_value)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot use a bytes pattern on a string-like object

JelleZijlstraand others added 2 commits November 5, 2022 07:53
>>> from unittest.case import TestCase
>>> c = TestCase()
>>> with c.assertRaisesRegex(Exception, b"x"): 1/0
...
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/case.py", line 274, in __exit__
if not expected_regex.search(str(exc_value)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot use a bytes pattern on a string-like object
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@hauntsaninja
hauntsaninja merged commit 1f76489 into python:mainNov 5, 2022
@AlexWaygood

Copy link
Copy Markdown
Member

sad, i always wanted to

@JelleZijlstra
JelleZijlstra deleted the unittest branch November 5, 2022 22:18
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@JelleZijlstra@AlexWaygood@hauntsaninja