Skip to content

Commit 191e8c6

Browse files
authored
Merge pull request #2969 from nicoddemus/null-bytes-2957
Always escape null bytes when setting PYTEST_CURRENT_TEST
2 parents 4d2f05e + 89cf943 commit 191e8c6

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

_pytest/runner.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from time import time
88

99
import py
10-
from _pytest.compat import _PY2
1110
from _pytest._code.code import TerminalRepr, ExceptionInfo
1211
from _pytest.outcomes import skip, Skipped, TEST_OUTCOME
1312

@@ -131,9 +130,8 @@ def _update_current_test_var(item, when):
131130
var_name = 'PYTEST_CURRENT_TEST'
132131
if when:
133132
value = '{0} ({1})'.format(item.nodeid, when)
134-
if _PY2:
135-
# python 2 doesn't like null bytes on environment variables (see #2644)
136-
value = value.replace('\x00', '(null)')
133+
# don't allow null bytes on environment variables (see #2644, #2957)
134+
value = value.replace('\x00', '(null)')
137135
os.environ[var_name] = value
138136
else:
139137
os.environ.pop(var_name)

changelog/2957.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Always escape null bytes when setting ``PYTEST_CURRENT_TEST``.

testing/acceptance_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,17 @@ def test_stuff(r):
415415
])
416416

417417
def test_parametrized_with_null_bytes(self, testdir):
418-
"""Test parametrization with values that contain null bytes and unicode characters (#2644)"""
418+
"""Test parametrization with values that contain null bytes and unicode characters (#2644, #2957)"""
419419
p = testdir.makepyfile(u"""
420420
# encoding: UTF-8
421421
import pytest
422422
423-
@pytest.mark.parametrize("data", ["\\x00", u'ação'])
423+
@pytest.mark.parametrize("data", [b"\\x00", "\\x00", u'ação'])
424424
def test_foo(data):
425425
assert data
426426
""")
427427
res = testdir.runpytest(p)
428-
res.assert_outcomes(passed=2)
428+
res.assert_outcomes(passed=3)
429429

430430

431431
class TestInvocationVariants(object):

0 commit comments

Comments
 (0)