File tree 3 files changed +24
-3
lines changed
3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change
1
+ Fix crash with captured output when using the :fixture: `capsysbinary fixture <capsysbinary> `.
Original file line number Diff line number Diff line change @@ -681,7 +681,8 @@ def resume(self):
681
681
setattr (sys , self .name , self .tmpfile )
682
682
self ._state = "resumed"
683
683
684
- def writeorg (self , data ):
684
+ def writeorg (self , data : str ) -> None :
685
+ data = data .decode (self ._old .encoding )
685
686
self ._old .write (data )
686
687
self ._old .flush ()
687
688
@@ -695,6 +696,10 @@ def snap(self):
695
696
self .tmpfile .truncate ()
696
697
return res
697
698
699
+ def writeorg (self , data : str ) -> None :
700
+ self ._old .write (data )
701
+ self ._old .flush ()
702
+
698
703
699
704
class TeeSysCapture (SysCapture ):
700
705
def __init__ (self , fd , tmpfile = None ):
Original file line number Diff line number Diff line change @@ -542,18 +542,33 @@ def test_hello(capfdbinary):
542
542
reprec .assertoutcome (passed = 1 )
543
543
544
544
def test_capsysbinary (self , testdir ):
545
- reprec = testdir .inline_runsource (
545
+ p1 = testdir .makepyfile (
546
546
"""\
547
547
def test_hello(capsysbinary):
548
548
import sys
549
+
549
550
# some likely un-decodable bytes
550
551
sys.stdout.buffer.write(b'\\ xfe\\ x98\\ x20')
552
+
551
553
out, err = capsysbinary.readouterr()
552
554
assert out == b'\\ xfe\\ x98\\ x20'
553
555
assert err == b''
556
+
557
+ # handles writing strings
558
+ print("hello")
559
+ print("hello stderr", file=sys.stderr)
554
560
"""
555
561
)
556
- reprec .assertoutcome (passed = 1 )
562
+ result = testdir .runpytest (str (p1 ), "-rA" )
563
+ result .stdout .fnmatch_lines (
564
+ [
565
+ "*- Captured stdout call -*" ,
566
+ "hello" ,
567
+ "*- Captured stderr call -*" ,
568
+ "hello stderr" ,
569
+ "*= 1 passed in *" ,
570
+ ]
571
+ )
557
572
558
573
def test_partial_setup_failure (self , testdir ):
559
574
p = testdir .makepyfile (
You can’t perform that action at this time.
0 commit comments