python unittest 문제점 본문

Programming

python unittest 문제점

halatha 2013. 1. 24. 13:29

상황
main.py: python main.py -arg1 val1 -arg2 ...와 같이 실행하는 main.py의 어떤 module을 테스트하고 싶음. 전역 logger 사용중이며, 전역 logger는 입력 인자가 있어야 할당

TestMain.py: def TestModule


문제점:실행시 필요한 인자를 어떻게 줄 것인가? 혹은 꼭 줘야만 테스트가 가능한가? 인자가 없이 module을 테스트하면 전역 logger가 할당되지 않아 module 내부에서 오류 발생


1) runpy.run_module

google 'python call main module from another' 'python run_module what to give init_globals'

http://docs.python.org/2/library/runpy.html?highlight=runpy#runpy.run_module

http://www.python.org/dev/peps/pep-0338/

http://stackoverflow.com/questions/2935862/python-idle-run-main


google 'python unittest set global name'

http://stackoverflow.com/questions/6271947/pyunit-simulating-input-to-stdin


2) main과 test할 method를 따로 import하고 unittest로 실행. 전역 logger는 setUp에서 할당

Comments