사용자 입력에 의존하여 테스트를 통과했는지 여부를 결정하는 몇 가지 테스트를 작성하고 있습니다.pytest가 사용자 입력을 대기 중임
def viewable(actual_proj):
print("\nCan you see %s projects named:\n"%len(actual_proj))
for i in actual_proj:
print (i+"\n")
return input("(y/n)? : ")
내 :
나는이 기능이
def is_present(pytestconfig, project_not_present = 0):
actual_projects = all_projects.copy()
if (project_not_present!=0):
del_file = all_ini_files[project_not_present-1]
os.rename(del_file, del_file +'_tst')
del actual_projects[project_not_present-1]
capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')
subprocess.Popen('./MultiPRM.exe')
capmanager.suspendcapture(in_=True)
decision = viewable(actual_projects)
capmanager.resumecapture()
if (project_not_present!=0):
os.rename(del_file+'_tst', del_file)
if (decision =='y'):
return True
else:
return False
내가 명령 pytest name_of_test_file.py
을 실행하면 잘 실행하고 사용자의 입력을 얻기 위해 각 테스트 후 중지합니다. 그러나, 나는이 방법을 실행하면 (run_tests.py
라고 함) 로그 파일에 대한 다양한 변수와 헤더를 설정하는 파일
# start the report
print("Creating test report: " + os.path.abspath(report_filepath))
rep = open(report_filepath, "w")
rep.write(report_header)
rep.write("Test environment: \n");
rep.write(" Username: " + os.environ['USERNAME'] + "\n")
rep.write("Testing started at: " + get_time() + "\n\n")
rep.close()
# get application version
cmd = exe_under_test + " --help >> " + report_filepath
os.system(cmd)
# start the tests
cmd = "pytest >> " + report_filepath
os.system(cmd)
# finalise the report
rep = open(report_filepath, "a+")
rep.write("\nTesting completed at: " + get_time() + "\n\n")
rep.close()
를 사용하려면, 그것은 중지 또는 테스트 중 하나를 실행되지 않습니다.
로그 파일에 쓸 수 있으면서 (사용자 입력 포함) 똑같은 것을 터미널에 쓰는 것이 좋습니다. 그렇지 않으면이 함수를 올바르게 호출하는 방법도 올바르게 작동합니다.
unittest의 요점은 사용자 상호 작용이 필요하지 않다는 것입니다. –
이 기능을 테스트 할 수있는 유일한 방법은 다음과 같습니다. 정확하지 않은 경우 –
사용자를 시뮬레이트하는 방법을 찾아야합니다 테스트 목적을위한 입력. 테스트 중 사용자 입력에 의존한다면 테스트를 실행하는 다른 사람이 당신과 동일한 것을 테스트하지 않을 수 있습니다. 테스트는 결정 론적이라고 가정합니다. – larsks