i am new to pytest and also python.
I have an issue which is whenever i run the test and generate log files, it will write to the log file but not append which causes i lost the previous logs.
I am trying out the example code now.
#conftest.py
#import os
def pytest_logger_config(logger_config):
logger_config.add_loggers(['foo', 'bar', 'baz'], stdout_level='info')
logger_config.set_log_option_default('foo,bar')
def pytest_logger_logdirlink(config):
return os.path.join(os.path.dirname(__file__), 'mylogs')
#test_something.py
import pytest
import logging
foo = logging.getLogger('foo')
bar = logging.getLogger('bar')
baz = logging.getLogger('baz')
@pytest.yield_fixture(scope='session')
def session_thing():
foo.debug('constructing session thing')
yield
foo.debug('destroying session thing')
@pytest.yield_fixture
def testcase_thing():
foo.debug('constructing testcase thing')
yield
foo.debug('destroying testcase thing')
def test_one(session_thing, testcase_thing):
foo.info('one executes')
bar.warning('this test does nothing aside from logging')
baz.info('extra log, rarely read')
def test_two(session_thing, testcase_thing):
foo.info('two executes')
bar.warning('neither does this')
baz.info('extra log, not enabled by default')
Anyone has good solution? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire