从python运行另一个python程序

从python运行另一个python程序,python,subprocess,Python,Subprocess,我试图构建一个测试脚本来测试我的python代码 被测试的代码应该从stdin读取并写入stdout 测试仪代码应将文件中传递值的测试代码调用为stdin,并读取stdout以与预期值(存储在另一个文件中)进行比较 测试代码: n = int(input()) x1,y1 = list(map(int, input().rstrip().split())) x2,y2 = list(map(int, input().rstrip().split())) #what it does is r

我试图构建一个测试脚本来测试我的python代码

被测试的代码应该从stdin读取并写入stdout

测试仪代码应将文件中传递值的测试代码调用为stdin,并读取stdout以与预期值(存储在另一个文件中)进行比较

测试代码:

n = int(input())
x1,y1 = list(map(int, input().rstrip().split())) 
x2,y2 = list(map(int, input().rstrip().split())) 

#what it does is really not importante
if ((min(x1, x2) <= n/2) and (max(x1, x2) > n/2) or
    (min(y1, y2) <= n/2) and (max(y1, y2) > n/2)):
    print('S')
else :
    print ('N')

我收到了以下多个错误(当禁用capture_输出以实现更好的可视化时):

当测试代码上只有一个
input()
时,上述方法有效。让它与多个
input()
一起工作,我缺少了什么?

您的代码适合我(只做了一些小改动)。它与
capture\u output=True
capture\u output=False

要运行的命令:

python3 tester.py
对于您的问题:我怀疑您的输入文件中某些行中可能缺少“\n”(可能是编辑器错误,不知道)

还可以尝试检查模块中的缩进
b.py


您可以将代码与输入文件共享以进行详细分析吗?

为什么要重复两次?x1 y1 x2 y2?调用输入文件时,只有3行,因此第4行是eof?
input()
应该只读取一行。我已经替换了
print(input())
的所有测试仪代码,并且按照预期只打印第一行输入。
Traceback (most recent call last):
  File "b.py", line 10, in <module>
    x1,y1 = list(map(int, input().rstrip().split())) 
  File "<string>", line 1
    5 2
      ^
SyntaxError: unexpected EOF while parsing
10
5 2
5 1
python3 tester.py