process = subprocess.Popen(command, shell=False, stdin=subprocess.PIPE,
    stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
stdout, stderr = process.communicate("""the user input
line 2""")
exit_status = process.wait()
How to supply stdin, files and environment variable inputs to Python unit tests?