Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Ondřej Súkup
Oscar Benjamin
Patrick Hayes
Pauli Virtanen
Pavel Karateev
Paweł Adamczak
Pedro Algarvio
Philipp Loose
Expand Down
2 changes: 2 additions & 0 deletions changelog/7126.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion src/_pytest/setuponly.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from _pytest._io.saferepr import saferepr


def pytest_addoption(parser):
Expand Down Expand Up @@ -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()

Expand Down
33 changes: 27 additions & 6 deletions testing/test_setuponly.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import pytest
from _pytest.config import ExitCode

Expand Down Expand Up @@ -146,10 +148,10 @@ def test_arg1(arg_other):

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'?",
]
)

Expand Down Expand Up @@ -179,7 +181,7 @@ def test_arg1(arg_other):
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'?"]
)


Expand All @@ -198,7 +200,9 @@ def test_foobar(foobar):
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):
Expand Down Expand Up @@ -292,3 +296,20 @@ def test_arg(arg):
]
)
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