Merge pull request #7205 from lancelote/7126

Issue 7126 - "saferepr" to avoid BytesWarning when using --setup-show
This commit is contained in:
Ran Benita 2020-05-14 16:04:22 +03:00 committed by GitHub
commit 2ac28f6c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 7 deletions

View File

@ -216,6 +216,7 @@ Ondřej Súkup
Oscar Benjamin
Patrick Hayes
Pauli Virtanen
Pavel Karateev
Paweł Adamczak
Pedro Algarvio
Philipp Loose

View File

@ -0,0 +1,2 @@
``--setup-show`` now doesn't raise an error when a bytes value is used as a ``parametrize``
parameter when Python is called with the ``-bb`` flag.

View File

@ -1,4 +1,5 @@
import pytest
from _pytest._io.saferepr import saferepr
def pytest_addoption(parser):
@ -66,7 +67,7 @@ def _show_fixture_action(fixturedef, msg):
tw.write(" (fixtures used: {})".format(", ".join(deps)))
if hasattr(fixturedef, "cached_param"):
tw.write("[{}]".format(fixturedef.cached_param))
tw.write("[{}]".format(saferepr(fixturedef.cached_param, maxsize=42)))
tw.flush()

View File

@ -1,3 +1,5 @@
import sys
import pytest
from _pytest.config import ExitCode
@ -146,10 +148,10 @@ def test_show_fixtures_with_parameters(testdir, mode):
result.stdout.fnmatch_lines(
[
"SETUP S arg_same?foo?",
"TEARDOWN S arg_same?foo?",
"SETUP S arg_same?bar?",
"TEARDOWN S arg_same?bar?",
"SETUP S arg_same?'foo'?",
"TEARDOWN S arg_same?'foo'?",
"SETUP S arg_same?'bar'?",
"TEARDOWN S arg_same?'bar'?",
]
)
@ -179,7 +181,7 @@ def test_show_fixtures_with_parameter_ids(testdir, mode):
assert result.ret == 0
result.stdout.fnmatch_lines(
["SETUP S arg_same?spam?", "SETUP S arg_same?ham?"]
["SETUP S arg_same?'spam'?", "SETUP S arg_same?'ham'?"]
)
@ -198,7 +200,9 @@ def test_show_fixtures_with_parameter_ids_function(testdir, mode):
result = testdir.runpytest(mode, p)
assert result.ret == 0
result.stdout.fnmatch_lines(["*SETUP F foobar?FOO?", "*SETUP F foobar?BAR?"])
result.stdout.fnmatch_lines(
["*SETUP F foobar?'FOO'?", "*SETUP F foobar?'BAR'?"]
)
def test_dynamic_fixture_request(testdir):
@ -292,3 +296,20 @@ def test_setup_show_with_KeyboardInterrupt_in_test(testdir):
]
)
assert result.ret == ExitCode.INTERRUPTED
def test_show_fixture_action_with_bytes(testdir):
# Issue 7126, BytesWarning when using --setup-show with bytes parameter
test_file = testdir.makepyfile(
"""
import pytest
@pytest.mark.parametrize('data', [b'Hello World'])
def test_data(data):
pass
"""
)
result = testdir.run(
sys.executable, "-bb", "-m", "pytest", "--setup-show", str(test_file)
)
assert result.ret == 0