일부 상태 변수를 검사하기 위해 테스트 함수 내에 일부 로깅 문을 넣고 싶습니다.py.test 테스트 내에서 로깅
나는 다음과 같은 코드를 가지고 :
import pytest,os
import logging
logging.basicConfig(level=logging.DEBUG)
mylogger = logging.getLogger()
#############################################################################
def setup_module(module):
''' Setup for the entire module '''
mylogger.info('Inside Setup')
# Do the actual setup stuff here
pass
def setup_function(func):
''' Setup for test functions '''
if func == test_one:
mylogger.info(' Hurray !!')
def test_one():
''' Test One '''
mylogger.info('Inside Test 1')
#assert 0 == 1
pass
def test_two():
''' Test Two '''
mylogger.info('Inside Test 2')
pass
if __name__ == '__main__':
mylogger.info(' About to start the tests ')
pytest.main(args=[os.path.abspath(__file__)])
mylogger.info(' Done executing the tests ')
나는 다음과 같은 출력을 얻을 다음 '__name__ == __main__'
블록 만 로깅 메시지가 콘솔로 전송받을
[bmaryada-mbp:/Users/bmaryada/dev/platform/main/proto/tests/tpch $]python minitest.py
INFO:root: About to start the tests
======================================================== test session starts =========================================================
platform darwin -- Python 2.6.2 -- pytest-2.0.0
collected 2 items
minitest.py ..
====================================================== 2 passed in 0.01 seconds ======================================================
INFO:root: Done executing the tests
공지 사항.
pytest가 테스트 메소드에서 콘솔 로깅을 강제로 내보내도록 할 수 있습니까? 나를 위해
py.test의 작성자가 게시 한 [this answer] (http://stackoverflow.com/a/11877951/148680)를 참조하십시오. 그는 고도의 다양성을 제공하는 pytest 플러그인을 제안합니다. – chb