File tree Expand file tree Collapse file tree 4 files changed +46
-5
lines changed Expand file tree Collapse file tree 4 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -267,5 +267,6 @@ Wouter van Ackooy
267
267
Xixi Zhao
268
268
Xuan Luong
269
269
Xuecong Liao
270
+ Yoav Caspi
270
271
Zac Hatfield-Dodds
271
272
Zoltán Máté
Original file line number Diff line number Diff line change
1
+ Fix crash with ``KeyboardInterrupt `` during ``--setup-show ``.
Original file line number Diff line number Diff line change 1
- import sys
2
-
3
1
import pytest
4
2
5
3
@@ -51,7 +49,6 @@ def _show_fixture_action(fixturedef, msg):
51
49
capman = config .pluginmanager .getplugin ("capturemanager" )
52
50
if capman :
53
51
capman .suspend_global_capture ()
54
- out , err = capman .read_global_capture ()
55
52
56
53
tw = config .get_terminal_writer ()
57
54
tw .line ()
@@ -74,8 +71,6 @@ def _show_fixture_action(fixturedef, msg):
74
71
75
72
if capman :
76
73
capman .resume_global_capture ()
77
- sys .stdout .write (out )
78
- sys .stderr .write (err )
79
74
80
75
81
76
@pytest .hookimpl (tryfirst = True )
Original file line number Diff line number Diff line change @@ -267,3 +267,47 @@ def test_arg(arg):
267
267
result .stdout .fnmatch_lines (
268
268
["*SETUP F arg*" , "*test_arg (fixtures used: arg)F*" , "*TEARDOWN F arg*" ]
269
269
)
270
+
271
+
272
+ def test_setup_show_with_KeyboardInterrupt_in_test (testdir ):
273
+ """ Verifies that setups are shown and tests are executed even if there was a KeyboardInterrupt in a test. """
274
+ p = testdir .makepyfile (
275
+ """
276
+ import pytest
277
+ @pytest.fixture
278
+ def arg():
279
+ assert True
280
+ def test_arg(arg):
281
+ raise KeyboardInterrupt()
282
+ """
283
+ )
284
+ result = testdir .runpytest ("--setup-show" , p , no_reraise_ctrlc = True )
285
+ assert result .ret == 2
286
+ result .stdout .fnmatch_lines (
287
+ [
288
+ "*SETUP F arg*" ,
289
+ "*test_arg (fixtures used: arg)*" ,
290
+ "*TEARDOWN F arg*" ,
291
+ "*! KeyboardInterrupt !*" ,
292
+ "*= no tests ran in *" ,
293
+ ]
294
+ )
295
+
296
+
297
+ def test_setup_show_with_KeyboardInterrupt_in_fixture (testdir ):
298
+ """ Verifies that setups are shown and tests are executed even if there was a KeyboardInterrupt in a fixture. """
299
+ p = testdir .makepyfile (
300
+ """
301
+ import pytest
302
+ @pytest.fixture
303
+ def arg():
304
+ raise KeyboardInterrupt()
305
+ def test_arg(arg):
306
+ assert True
307
+ """
308
+ )
309
+ result = testdir .runpytest ("--setup-show" , p , no_reraise_ctrlc = True )
310
+ assert result .ret == 2
311
+ result .stdout .fnmatch_lines (
312
+ ["*SETUP F arg*" , "*! KeyboardInterrupt !*" , "*= no tests ran in *" ]
313
+ )
You can’t perform that action at this time.
0 commit comments