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 @@ -267,5 +267,6 @@ Wouter van Ackooy
Xixi Zhao
Xuan Luong
Xuecong Liao
Yoav Caspi
Zac Hatfield-Dodds
Zoltán Máté
1 change: 1 addition & 0 deletions changelog/5906.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash with ``KeyboardInterrupt`` during ``--setup-show``.
2 changes: 1 addition & 1 deletion doc/en/example/parametrize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,4 @@ Or, if desired, you can ``pip install contextlib2`` and use:

.. code-block:: python

from contextlib2 import ExitStack as does_not_raise
from contextlib2 import nullcontext as does_not_raise
2 changes: 1 addition & 1 deletion src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _ensure_supporting_files(self):
readme_path.write_text(README_CONTENT)

gitignore_path = self._cachedir.joinpath(".gitignore")
msg = "# Created by pytest automatically.\n*"
msg = "# Created by pytest automatically.\n*\n"
gitignore_path.write_text(msg, encoding="UTF-8")

cachedir_tag_path = self._cachedir.joinpath("CACHEDIR.TAG")
Expand Down
5 changes: 0 additions & 5 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def get_plugin_manager():


def _prepareconfig(args=None, plugins=None):
warning = None
if args is None:
args = sys.argv[1:]
elif isinstance(args, py.path.local):
Expand All @@ -213,10 +212,6 @@ def _prepareconfig(args=None, plugins=None):
pluginmanager.consider_pluginarg(plugin)
else:
pluginmanager.register(plugin)
if warning:
from _pytest.warnings import _issue_warning_captured

_issue_warning_captured(warning, hook=config.hook, stacklevel=4)
return pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args
)
Expand Down
5 changes: 0 additions & 5 deletions src/_pytest/setuponly.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

import pytest


Expand Down Expand Up @@ -51,7 +49,6 @@ def _show_fixture_action(fixturedef, msg):
capman = config.pluginmanager.getplugin("capturemanager")
if capman:
capman.suspend_global_capture()
out, err = capman.read_global_capture()

tw = config.get_terminal_writer()
tw.line()
Expand All @@ -74,8 +71,6 @@ def _show_fixture_action(fixturedef, msg):

if capman:
capman.resume_global_capture()
sys.stdout.write(out)
sys.stderr.write(err)


@pytest.hookimpl(tryfirst=True)
Expand Down
2 changes: 1 addition & 1 deletion testing/test_cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ def test_gitignore(testdir):
config = testdir.parseconfig()
cache = Cache.for_config(config)
cache.set("foo", "bar")
msg = "# Created by pytest automatically.\n*"
msg = "# Created by pytest automatically.\n*\n"
gitignore_path = cache._cachedir.joinpath(".gitignore")
assert gitignore_path.read_text(encoding="UTF-8") == msg

Expand Down
25 changes: 25 additions & 0 deletions testing/test_setuponly.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from _pytest.main import ExitCode


@pytest.fixture(params=["--setup-only", "--setup-plan", "--setup-show"], scope="module")
Expand Down Expand Up @@ -267,3 +268,27 @@ def test_arg(arg):
result.stdout.fnmatch_lines(
["*SETUP F arg*", "*test_arg (fixtures used: arg)F*", "*TEARDOWN F arg*"]
)


def test_setup_show_with_KeyboardInterrupt_in_test(testdir):
p = testdir.makepyfile(
"""
import pytest
@pytest.fixture
def arg():
pass
def test_arg(arg):
raise KeyboardInterrupt()
"""
)
result = testdir.runpytest("--setup-show", p, no_reraise_ctrlc=True)
result.stdout.fnmatch_lines(
[
"*SETUP F arg*",
"*test_arg (fixtures used: arg)*",
"*TEARDOWN F arg*",
"*! KeyboardInterrupt !*",
"*= no tests ran in *",
]
)
assert result.ret == ExitCode.INTERRUPTED