Skip to content

Commit 978c7ae

Browse files
authored
Merge pull request #6015 from blueyed/merge-master-into-features
Merge master into features
2 parents fbb7f66 + 803cc1f commit 978c7ae

File tree

8 files changed

+30
-13
lines changed

8 files changed

+30
-13
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,6 @@ Wouter van Ackooy
267267
Xixi Zhao
268268
Xuan Luong
269269
Xuecong Liao
270+
Yoav Caspi
270271
Zac Hatfield-Dodds
271272
Zoltán Máté

changelog/5906.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash with ``KeyboardInterrupt`` during ``--setup-show``.

doc/en/example/parametrize.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,4 +678,4 @@ Or, if desired, you can ``pip install contextlib2`` and use:
678678

679679
.. code-block:: python
680680
681-
from contextlib2 import ExitStack as does_not_raise
681+
from contextlib2 import nullcontext as does_not_raise

src/_pytest/cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _ensure_supporting_files(self):
135135
readme_path.write_text(README_CONTENT)
136136

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

141141
cachedir_tag_path = self._cachedir.joinpath("CACHEDIR.TAG")

src/_pytest/config/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def get_plugin_manager():
195195

196196

197197
def _prepareconfig(args=None, plugins=None):
198-
warning = None
199198
if args is None:
200199
args = sys.argv[1:]
201200
elif isinstance(args, py.path.local):
@@ -213,10 +212,6 @@ def _prepareconfig(args=None, plugins=None):
213212
pluginmanager.consider_pluginarg(plugin)
214213
else:
215214
pluginmanager.register(plugin)
216-
if warning:
217-
from _pytest.warnings import _issue_warning_captured
218-
219-
_issue_warning_captured(warning, hook=config.hook, stacklevel=4)
220215
return pluginmanager.hook.pytest_cmdline_parse(
221216
pluginmanager=pluginmanager, args=args
222217
)

src/_pytest/setuponly.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
import pytest
42

53

@@ -51,7 +49,6 @@ def _show_fixture_action(fixturedef, msg):
5149
capman = config.pluginmanager.getplugin("capturemanager")
5250
if capman:
5351
capman.suspend_global_capture()
54-
out, err = capman.read_global_capture()
5552

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

7572
if capman:
7673
capman.resume_global_capture()
77-
sys.stdout.write(out)
78-
sys.stderr.write(err)
7974

8075

8176
@pytest.hookimpl(tryfirst=True)

testing/test_cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ def test_gitignore(testdir):
10291029
config = testdir.parseconfig()
10301030
cache = Cache.for_config(config)
10311031
cache.set("foo", "bar")
1032-
msg = "# Created by pytest automatically.\n*"
1032+
msg = "# Created by pytest automatically.\n*\n"
10331033
gitignore_path = cache._cachedir.joinpath(".gitignore")
10341034
assert gitignore_path.read_text(encoding="UTF-8") == msg
10351035

testing/test_setuponly.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from _pytest.main import ExitCode
23

34

45
@pytest.fixture(params=["--setup-only", "--setup-plan", "--setup-show"], scope="module")
@@ -267,3 +268,27 @@ def test_arg(arg):
267268
result.stdout.fnmatch_lines(
268269
["*SETUP F arg*", "*test_arg (fixtures used: arg)F*", "*TEARDOWN F arg*"]
269270
)
271+
272+
273+
def test_setup_show_with_KeyboardInterrupt_in_test(testdir):
274+
p = testdir.makepyfile(
275+
"""
276+
import pytest
277+
@pytest.fixture
278+
def arg():
279+
pass
280+
def test_arg(arg):
281+
raise KeyboardInterrupt()
282+
"""
283+
)
284+
result = testdir.runpytest("--setup-show", p, no_reraise_ctrlc=True)
285+
result.stdout.fnmatch_lines(
286+
[
287+
"*SETUP F arg*",
288+
"*test_arg (fixtures used: arg)*",
289+
"*TEARDOWN F arg*",
290+
"*! KeyboardInterrupt !*",
291+
"*= no tests ran in *",
292+
]
293+
)
294+
assert result.ret == ExitCode.INTERRUPTED

0 commit comments

Comments
 (0)