When a regex pattern contains bytes instead of a string use escape_encode to turn it into a string before further processing. Thanks @nicoddemus for the review and tips!
This commit is contained in:
parent
9b51536a18
commit
8ce32b0795
1
AUTHORS
1
AUTHORS
|
@ -59,6 +59,7 @@ Marc Schlaich
|
||||||
Mark Abramowitz
|
Mark Abramowitz
|
||||||
Markus Unterwaditzer
|
Markus Unterwaditzer
|
||||||
Martijn Faassen
|
Martijn Faassen
|
||||||
|
Matt Bachmann
|
||||||
Michael Aquilina
|
Michael Aquilina
|
||||||
Michael Birtwell
|
Michael Birtwell
|
||||||
Michael Droettboom
|
Michael Droettboom
|
||||||
|
|
|
@ -8,17 +8,19 @@
|
||||||
* Fix (`#469`_): junit parses report.nodeid incorrectly, when params IDs
|
* Fix (`#469`_): junit parses report.nodeid incorrectly, when params IDs
|
||||||
contain ``::``. Thanks `@tomviner`_ for the PR (`#1431`_).
|
contain ``::``. Thanks `@tomviner`_ for the PR (`#1431`_).
|
||||||
|
|
||||||
*
|
|
||||||
|
|
||||||
* Fix (`#578 <https://github.com/pytest-dev/pytest/issues/578>`_): SyntaxErrors
|
* Fix (`#578 <https://github.com/pytest-dev/pytest/issues/578>`_): SyntaxErrors
|
||||||
containing non-ascii lines at the point of failure generated an internal
|
containing non-ascii lines at the point of failure generated an internal
|
||||||
py.test error.
|
py.test error.
|
||||||
Thanks `@asottile`_ for the report and `@nicoddemus`_ for the PR.
|
Thanks `@asottile`_ for the report and `@nicoddemus`_ for the PR.
|
||||||
|
|
||||||
*
|
* Fix (`#1437`_): When passing in a bytestring regex pattern to parameterize
|
||||||
|
attempt to decode it as utf-8 ignoring errors.
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
|
.. _#1437: https://github.com/pytest-dev/pytest/issues/1437
|
||||||
.. _#469: https://github.com/pytest-dev/pytest/issues/469
|
.. _#469: https://github.com/pytest-dev/pytest/issues/469
|
||||||
.. _#1431: https://github.com/pytest-dev/pytest/pull/1431
|
.. _#1431: https://github.com/pytest-dev/pytest/pull/1431
|
||||||
|
|
||||||
|
|
|
@ -1115,7 +1115,7 @@ def _idval(val, argname, idx, idfn):
|
||||||
elif isinstance(val, (float, int, str, bool, NoneType)):
|
elif isinstance(val, (float, int, str, bool, NoneType)):
|
||||||
return str(val)
|
return str(val)
|
||||||
elif isinstance(val, REGEX_TYPE):
|
elif isinstance(val, REGEX_TYPE):
|
||||||
return val.pattern
|
return _escape_bytes(val.pattern) if isinstance(val.pattern, bytes) else val.pattern
|
||||||
elif enum is not None and isinstance(val, enum.Enum):
|
elif enum is not None and isinstance(val, enum.Enum):
|
||||||
return str(val)
|
return str(val)
|
||||||
elif isclass(val) and hasattr(val, '__name__'):
|
elif isclass(val) and hasattr(val, '__name__'):
|
||||||
|
|
|
@ -392,6 +392,20 @@ class TestGeneralUsage:
|
||||||
monkeypatch.setitem(sys.modules, 'myplugin', mod)
|
monkeypatch.setitem(sys.modules, 'myplugin', mod)
|
||||||
assert pytest.main(args=[str(tmpdir)], plugins=['myplugin']) == 0
|
assert pytest.main(args=[str(tmpdir)], plugins=['myplugin']) == 0
|
||||||
|
|
||||||
|
def test_parameterized_with_bytes_regex(self, testdir):
|
||||||
|
p = testdir.makepyfile("""
|
||||||
|
import re
|
||||||
|
import pytest
|
||||||
|
@pytest.mark.parametrize('r', [re.compile(b'foo')])
|
||||||
|
def test_stuff(r):
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
res = testdir.runpytest(p)
|
||||||
|
res.stdout.fnmatch_lines([
|
||||||
|
'*1 passed*'
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class TestInvocationVariants:
|
class TestInvocationVariants:
|
||||||
def test_earlyinit(self, testdir):
|
def test_earlyinit(self, testdir):
|
||||||
|
|
|
@ -170,6 +170,11 @@ class TestMetafunc:
|
||||||
result = idmaker((py.builtin._totext("a"), "b"), [({}, b'\xc3\xb4')])
|
result = idmaker((py.builtin._totext("a"), "b"), [({}, b'\xc3\xb4')])
|
||||||
assert result == ['a0-\\xc3\\xb4']
|
assert result == ['a0-\\xc3\\xb4']
|
||||||
|
|
||||||
|
def test_idmaker_with_bytes_regex(self):
|
||||||
|
from _pytest.python import idmaker
|
||||||
|
result = idmaker(("a"), [(re.compile(b'foo'), 1.0)])
|
||||||
|
assert result == ["foo"]
|
||||||
|
|
||||||
def test_idmaker_native_strings(self):
|
def test_idmaker_native_strings(self):
|
||||||
from _pytest.python import idmaker
|
from _pytest.python import idmaker
|
||||||
totext = py.builtin._totext
|
totext = py.builtin._totext
|
||||||
|
|
Loading…
Reference in New Issue