일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- Spain
- France
- Malaysia
- history
- comic agile
- erlang
- ubuntu
- program
- leadership
- Book review
- Python
- Programming
- Software Engineering
- Artificial Intelligence
- hbase
- agile
- essay
- hadoop
- Italy
- Kuala Lumpur
- web
- django
- programming_book
- RFID
- QT
- Java
- Book
- Linux
- management
- MySQL
- Today
- Total
python unittest 문제점 본문
상황
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에서 할당