小编Kan*_*ros的帖子

成功测试用例后删除py.test tmpdir目录

我正在运行在执行期间创建大量大文件的测试.为此,如果测试已通过,我想删除tmpdir目录.但如果测试失败,则应保持tmpdir的内容不变.

我知道如何确定测试结果:

from _pytest.runner import runtestprotocol

def pytest_runtest_protocol(item, nextitem):
    reports = runtestprotocol(item, nextitem=nextitem)
    for report in reports:
        if report.when == 'call':
            # value will be set to passed or filed
            test_outcome = report.outcome
            # But what next?

return True
Run Code Online (Sandbox Code Playgroud)

但我不知道如何找出创建的tmpdir目录的路径.

python pytest

7
推荐指数
1
解决办法
3622
查看次数

有没有办法找出哪个pytest-xdist网关正在运行?

我想为pytest-xdist产生的每个子进程/网关创建一个单独的日志文件。是否有一种优雅的方法来找出当前在哪个子进程/网关pytest中?我正在使用位于中的会话作用域夹具来配置我的根记录器conftest.py,如下所示:

@pytest.fixture(scope='session', autouse=True)
def setup_logging():
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO)

    fh = logging.FileHandler('xdist.log')
    fh.setLevel(logging.INFO)

   formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
   fh.setFormatter(formatter)

   logger.addHandler(fh)
Run Code Online (Sandbox Code Playgroud)

如果我可以根据网关号在日志文件名中添加前缀,那就太好了,例如:

 fh = logging.FileHandler('xdist_gateway_%s.log' % gateway_number)
Run Code Online (Sandbox Code Playgroud)

没有此网关,每个网关将使用相同的日志,并且日志将变得混乱。我知道我可以在文件名中添加时间戳。但这不能让我快速区分哪个文件来自哪个网关。

pytest

5
推荐指数
1
解决办法
777
查看次数

标签 统计

pytest ×2

python ×1