Skip to content

Commit afda920

Browse files
pilou-philpep
authored andcommitted
Remove encoding parameter when binary mode is used
Fix this exception: python3 -c "import sys; from testinfra.plugin import SpooledTemporaryFile;\ SpooledTemporaryFile(encoding=sys.stdout.encoding).fileno()" Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/lib/python3.8/tempfile.py", line 839, in fileno self.rollover() File "/usr/lib/python3.8/tempfile.py", line 793, in rollover newfile = self._file = TemporaryFile(**self._TemporaryFileArgs) File "/usr/lib/python3.8/tempfile.py", line 744, in TemporaryFile return _io.open(fd, mode, buffering=buffering, ValueError: binary mode doesn't take an encoding argument
1 parent 5e72c2e commit afda920

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

testinfra/plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ def report(self):
167167
class SpooledTemporaryFile(tempfile.SpooledTemporaryFile):
168168

169169
def __init__(self, *args, **kwargs):
170-
self._out_encoding = kwargs['encoding']
170+
if 'b' in kwargs.get('mode', 'b'):
171+
self._out_encoding = kwargs.pop('encoding')
172+
else:
173+
self._out_encoding = kwargs.get('encoding')
171174
super().__init__(*args, **kwargs)
172175

173176
def write(self, s):

0 commit comments

Comments
 (0)