unittest를 가져오고 일부 TestCases가있는 모듈이 있습니다. 일부 명령 행 옵션 (예 : 아래의 데이터 파일 이름)을 허용하려면, 하지만 옵션을 전달하려고 할 때 "옵션 -i not recognized"메시지가 나타납니다. unittest + 앱에 옵션을 제공 할 수 있습니까 (참고 : 옵션을 처리하기 위해 optparse를 사용하고 있습니다)? 감사.python, unittest : 명령 행 옵션을 앱에 전달하는 방법이 있나요
$ python test_app_data.py -i data_1.txt
option -i not recognized
=====================
후속은 :
import cfg_master #has the optparse option-handling code
...
if __name__ == '__main__':
#add you app's options here...
options_tpl = ('-i', '--in_dir', '-o', '--out_dir')
del_lst = []
for i,option in enumerate(sys.argv):
if option in options_tpl:
del_lst.append(i)
del_lst.append(i+1)
del_lst.reverse()
for i in del_lst:
del sys.argv[i]
unittest.main()
:이 제안 된 솔루션의 구현입니다 당신이
unittest
코드에 제어를 전달하기 전에 후자의 코드가 명령 행 옵션을 해석하려고하지 않도록 당신이 우리를 표시하지 않는 당신의
if __name__ == '__main__':
섹션에서
을 unittest.main 호출합니다. 이 경우 응답은 사용자가 제공하지 않은 세부 정보에 크게 의존합니다. –
@jd. 귀하의 "후속 조치"가 답변으로 게시되어야합니다. 귀하의 질문에는 ... 잘 ... 질문 만 포함되어야합니다. – user1251007