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

Bug #1845631 reported by serenico on 2019-09-27
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
subunit
Undecided
Unassigned
testtools
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

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers