title: How to unit test stream generators
body: <p>I am setting up unit tests for my flask app. A lot of my functions streams the output to the gui like this one:</p>
  
  <pre><code>def stream():
      def generate():
          if request.method == "POST":
              hostname = request.data.decode('utf-8')
              hostname_dn = "{}.{}".format(hostname, DOMAIN)
  
              logging.info("Connecting to: {}".format(hostname_dn))
  
              # Connect to hostname and execute create reports
              client = set_up_client()
              client.connect(hostname_dn,
                             username=USERNAME,
                             password=PASSWORD)
  
              cmd = ('tail -f -n0 /home/server.log')
  
              stdin, stdout, stderr = client.exec_command(cmd)
  
              for line in iter(lambda: stdout.readline(2048), ""):
                  logging.info(line, end="")
                  yield line
                  if re.search(r'keyword', line):
                      yield 'keyword detected\n'
                      break
  
      return Response(stream_with_context(generate()), mimetype='text/html')
  </code></pre>
  
  <p>My question is how could I use <code>assert</code> statements to verify these functions? Since they return a stream response. Is there a way I can slap on an extra parameter in the return statement like 200 or something then use assert to verify the stream was successful?</p>