@@ -2100,11 +2100,13 @@ def setUp(self):
21002100 self .result = TextTestResult (io .StringIO ())
21012101
21022102 def getvalue (self ):
2103+ assert isinstance (self .result .stream , io .StringIO )
21032104 return self .result .stream .getvalue ()
21042105
21052106 def test__init_sets_stream (self ):
2106- result = TextTestResult ("fp" )
2107- self .assertEqual ("fp" , result .stream )
2107+ stream = io .StringIO ()
2108+ result = TextTestResult (stream )
2109+ self .assertEqual (stream , result .stream )
21082110
21092111 def reset_output (self ):
21102112 self .result .stream = io .StringIO ()
@@ -2277,6 +2279,7 @@ def __init__(self, stream):
22772279
22782280 def addSuccess (self , test , details = None ):
22792281 super ().addSuccess (test , details )
2282+ assert self .stream is not None
22802283 self .stream .write ("CUSTOM_SUCCESS_MARKER\n " )
22812284
22822285 stream = io .StringIO ()
@@ -3554,7 +3557,7 @@ def test_no_details(self):
35543557
35553558 def test_binary_content (self ):
35563559 content = content_from_stream (
3557- io .StringIO ( "foo" ), content_type = ContentType ("image" , "jpeg" )
3560+ io .BytesIO ( b "foo" ), content_type = ContentType ("image" , "jpeg" )
35583561 )
35593562 string = _details_to_str ({"attachment" : content })
35603563 self .assertThat (
@@ -3609,16 +3612,16 @@ def test_empty_attachment(self):
36093612 )
36103613
36113614 def test_lots_of_different_attachments (self ):
3612- def jpg (x ) :
3613- return content_from_stream (io .StringIO (x ), ContentType ("image" , "jpeg" ))
3615+ def jpg (x : bytes ) -> Content :
3616+ return content_from_stream (io .BytesIO (x ), ContentType ("image" , "jpeg" ))
36143617
36153618 attachments = {
36163619 "attachment" : text_content ("foo" ),
36173620 "attachment-1" : text_content ("traceback" ),
3618- "attachment-2" : jpg ("pic1" ),
3621+ "attachment-2" : jpg (b "pic1" ),
36193622 "attachment-3" : text_content ("bar" ),
36203623 "attachment-4" : text_content ("" ),
3621- "attachment-5" : jpg ("pic2" ),
3624+ "attachment-5" : jpg (b "pic2" ),
36223625 }
36233626 string = _details_to_str (attachments , special = "attachment-1" )
36243627 self .assertThat (
0 commit comments