import sys import subprocess import unittest class StdinTests(unittest.TestCase): def simplescript(self, script, expected): with subprocess.Popen( ["cmd.exe", "/C", 'echo', 'test', "|", sys.executable, "-c", script], stdout=subprocess.PIPE) as proc: proc.wait() output = proc.stdout.read() self.assertEqual(expected, output) def test_input(self): self.simplescript("print(repr(input()))", b"'test '\n") def test_stdin(self): self.simplescript("import sys;print(list(sys.stdin))", b"['test \\n']\n") if __name__=='__main__': unittest.main()