Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17245

How can I unit test the log file?

$
0
0

I must run the script below by hand $ python -m mylog in order to test logging.

Why does $ pytest -s fail creating the logfile?

#mylog.pyimport loggingdef foobar(logfile):    logging.basicConfig(filename=logfile, level=logging.DEBUG)    logging.debug('This message should go to the log file')    logging.info('So should this')    logging.warning('And this, too')    logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
#test_mylog.pyfrom . import mylogfrom pathlib import Pathdef test_mylog():    logfile='./mylog.log'    mylog.foobar(logfile)    assert Path(logfile).exists()
>>> AssertionError: assert False

Viewing all articles
Browse latest Browse all 17245

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>