@@ -208,7 +208,8 @@ def test_init_capturing(self):
208208 try :
209209 capman = CaptureManager (CaptureMethod .FD )
210210 capman .start_capturing ()
211- pytest .raises (AssertionError , capman .start_capturing )
211+ with pytest .raises (AssertionError ):
212+ capman .start_capturing ()
212213 capman .stop_capturing ()
213214 finally :
214215 capouter .stop_capturing ()
@@ -364,7 +365,8 @@ def test_text(self):
364365 def test_unicode_and_str_mixture (self ):
365366 f = capture .CaptureIO ()
366367 f .write ("\u00f6 " )
367- pytest .raises (TypeError , f .write , b"hello" )
368+ with pytest .raises (TypeError ):
369+ f .write (b"hello" )
368370
369371 def test_write_bytes_to_buffer (self ):
370372 """In python3, stdout / stderr are text io wrappers (exposing a buffer property
@@ -394,7 +396,8 @@ def test_unicode_and_str_mixture(self):
394396 sio = io .StringIO ()
395397 f = capture .TeeCaptureIO (sio )
396398 f .write ("\u00f6 " )
397- pytest .raises (TypeError , f .write , b"hello" )
399+ with pytest .raises (TypeError ):
400+ f .write (b"hello" )
398401
399402
400403def test_dontreadfrominput ():
@@ -403,11 +406,15 @@ def test_dontreadfrominput():
403406 f = DontReadFromInput ()
404407 assert f .buffer is f
405408 assert not f .isatty ()
406- pytest .raises (OSError , f .read )
407- pytest .raises (OSError , f .readlines )
409+ with pytest .raises (OSError ):
410+ f .read ()
411+ with pytest .raises (OSError ):
412+ f .readlines ()
408413 iter_f = iter (f )
409- pytest .raises (OSError , next , iter_f )
410- pytest .raises (UnsupportedOperation , f .fileno )
414+ with pytest .raises (OSError ):
415+ next (iter_f )
416+ with pytest .raises (UnsupportedOperation ):
417+ f .fileno ()
411418 f .close () # just for completeness
412419
413420
@@ -474,7 +481,8 @@ def test_simple(self, tmpfile):
474481 cap = capture .FDCapture (fd )
475482 data = b"hello"
476483 os .write (fd , data )
477- pytest .raises (AssertionError , cap .snap )
484+ with pytest .raises (AssertionError ):
485+ cap .snap ()
478486 cap .done ()
479487 cap = capture .FDCapture (fd )
480488 cap .start ()
@@ -495,7 +503,8 @@ def test_simple_fail_second_start(self, tmpfile):
495503 fd = tmpfile .fileno ()
496504 cap = capture .FDCapture (fd )
497505 cap .done ()
498- pytest .raises (AssertionError , cap .start )
506+ with pytest .raises (AssertionError ):
507+ cap .start ()
499508
500509 def test_stderr (self ):
501510 cap = capture .FDCapture (2 )
@@ -546,7 +555,8 @@ def test_simple_resume_suspend(self):
546555 assert s == "but now yes\n "
547556 cap .suspend ()
548557 cap .done ()
549- pytest .raises (AssertionError , cap .suspend )
558+ with pytest .raises (AssertionError ):
559+ cap .suspend ()
550560
551561 assert repr (cap ) == (
552562 "<FDCapture 1 oldfd={} _state='done' tmpfile={!r}>" .format ( # noqa: UP032
@@ -631,7 +641,8 @@ def test_reset_twice_error(self):
631641 with self .getcapture () as cap :
632642 print ("hello" )
633643 out , err = cap .readouterr ()
634- pytest .raises (ValueError , cap .stop_capturing )
644+ with pytest .raises (ValueError ):
645+ cap .stop_capturing ()
635646 assert out == "hello\n "
636647 assert not err
637648
@@ -688,8 +699,8 @@ def test_stdin_nulled_by_default(self):
688699 print ("XX this test may well hang instead of crashing" )
689700 print ("XX which indicates an error in the underlying capturing" )
690701 print ("XX mechanisms" )
691- with self .getcapture ():
692- pytest . raises ( OSError , sys .stdin .read )
702+ with self .getcapture (), pytest . raises ( OSError ) :
703+ sys .stdin .read ( )
693704
694705
695706class TestTeeStdCapture (TestStdCapture ):
@@ -829,6 +840,5 @@ def test_fdcapture_invalid_fd_without_fd_reuse(self, tmp_path):
829840
830841def test__get_multicapture () -> None :
831842 assert isinstance (_get_multicapture (CaptureMethod .NO ), MultiCapture )
832- pytest .raises (ValueError , _get_multicapture , "unknown" ).match (
833- r"^unknown capturing method: 'unknown'"
834- )
843+ with pytest .raises (ValueError , match = r"^unknown capturing method: 'unknown'" ):
844+ _get_multicapture ("unknown" )
0 commit comments