其他分享
首页 > 其他分享> > pytest中自动计算每个用例执行的时间,参考官网

pytest中自动计算每个用例执行的时间,参考官网

作者:互联网

官网

conftest.py

import pytest
import time
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'


@pytest.fixture(scope='session', autouse=True)
def timer_session_scope():
    start = time.time()
    print('\nstart: {}'.format(time.strftime(DATE_FORMAT, time.localtime(start))))

    yield

    finished = time.time()
    print('finished: {}'.format(time.strftime(DATE_FORMAT, time.localtime(finished))))
    print('Total time cost: {:.3f}s'.format(finished - start))


@pytest.fixture(autouse=True)
def timer_function_scope():
    start = time.time()
    yield
    print(' Time cost: {:.3f}s'.format(time.time() - start))

标签:format,用例,finished,pytest,time,print,官网,start
来源: https://www.cnblogs.com/tarzen213/p/16433973.html