subunit fails to write to stream when write() returns None

Bug #1845631 reported by serenico
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
subunit
Incomplete
Undecided
Unassigned
testtools
Incomplete
Undecided
Unassigned

Bug Description

A purely implement filelike object doesn't implements write method without returning None instead of the actual number of written bytes. This would make below code to broke on python >= 3. becouse trying to sum None to an integer.

https://github.com/testing-cabal/subunit/blob/8cdd703980c314dddf95cc0556f67bc80358ddcd/python/subunit/v2.py#L225-L226

  # On eventlet 0.17.3, GreenIO.write() can make partial write.
  # Use a loop to ensure that all bytes are written.
  # See also the eventlet issue:
  # https://github.com/eventlet/eventlet/issues/248
  view = memoryview(data)
  datalen = len(data)
  offset = 0
  while offset < datalen:
      written = self.output_stream.write(view[offset:])
      offset += written

The workaround for such problem is to check value returned from write method and if it is None to assume all bytes has been written.

  while offset < datalen:
      written = self.output_stream.write(view[offset:])
      if written is None:
          break
      offset += written

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

I'm not sure I follow; Aren't write() methods meant to return the number of bytes written?

Changed in subunit:
status: New → Incomplete
Changed in testtools:
status: New → Incomplete
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.