使用PyTest

时间:2019-05-27 08:34:02

标签: python logging filesystems pytest

我是PyTest的新手。
我想使用PyTest运行测试,并为每个测试创建它在其中运行一个特殊文件夹的方法。
我为此使用了日志记录程序包,并且执行了以下实现:

#!/usr/bin/python2

import logging


log_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"

formatter = logging.Formatter(log_format)
# THIS WILL CREATE ME A temp.log file inside current directory
file = logging.FileHandler('./temp.log')
# ATTACHING THE LOG FORMAT TO THIS LOG FILE HANDLER
file.setFormatter(formatter)
line_format = '%(asctime)s %(levelname)s  %(name)s - %(message)s'

# Create logger and attach the file handler to it
general = logging.getLogger("info_logger")
general.addHandler(fh)
...

,正在使用记录仪的测试如下:

def test():
    general.debug('debugging test')
    general.debug('still 'debugging')
    general.info('debug is on')
    general.warning('probably will fail to debug')
    general.debug('nothing to print')

通过这种方法,我实际上可以创建如下所示的temp.log文件:

2019-05-27 10:24:56,381 [   DEBUG] debugging test(test.py:22)
2019-05-27 10:24:56,382 [   DEBUG] still debugging (test.py:29)
2019-05-27 10:24:56,383 [    INFO] debug is on (test.py:35)
2019-05-27 10:24:56,383 [ WARNING] probably will fail to debug (test.py:36)
2019-05-27 10:24:56,384 [   DEBUG] nothing to print(test.py:37)

现在,我的问题是:
1)是否有另一种使用PyTest并可以创建请求的功能的方法(不是创建文件处理程序的方法)
2)与此描述无关,如何使用python连接到另一个FS(从Ubuntu到Windows)并创建目录并在另一个FS中写入它们(类似于使用CIFS写入第二个FS)。

0 个答案:

没有答案