小编sup*_*tor的帖子

在py.test测试中记录

我想在测试函数中放入一些日志语句来检查一些状态变量.

我有以下代码片段:

import pytest,os
import logging

logging.basicConfig(level=logging.DEBUG)
mylogger = logging.getLogger()

#############################################################################

def setup_module(module):
    ''' Setup for the entire module '''
    mylogger.info('Inside Setup')
    # Do the actual setup stuff here
    pass

def setup_function(func):
    ''' Setup for test functions '''
    if func == test_one:
        mylogger.info(' Hurray !!')

def test_one():
    ''' Test One '''
    mylogger.info('Inside Test 1')
    #assert 0 == 1
    pass

def test_two():
    ''' Test Two '''
    mylogger.info('Inside Test 2')
    pass

if __name__ == '__main__':
    mylogger.info(' About to start the tests ') …
Run Code Online (Sandbox Code Playgroud)

python logging pytest

66
推荐指数
5
解决办法
4万
查看次数

有没有办法控制pytest-xdist如何并行运行测试?

我有以下目录布局:

runner.py
lib/
tests/
      testsuite1/
                 testsuite1.py
      testsuite2/
                 testsuite2.py
      testsuite3/
                 testsuite3.py
      testsuite4/
                 testsuite4.py
Run Code Online (Sandbox Code Playgroud)

testsuite*.py模块的格式如下:

import pytest 
class testsomething:
      def setup_class(self):
          ''' do some setup '''
          # Do some setup stuff here      
      def teardown_class(self):
          '''' do some teardown'''
          # Do some teardown stuff here

      def test1(self):
          # Do some test1 related stuff

      def test2(self):
          # Do some test2 related stuff

      ....
      ....
      ....
      def test40(self):
          # Do some test40 related stuff

if __name__=='__main()__'
   pytest.main(args=[os.path.abspath(__file__)])

我遇到的问题是我想并行执行'testsuites',即我希望testsuite1,testsuite2,testsuite3和testsuite4并行开始执行,但是测试套件中的单个测试需要连续执行.

当我使用py.test中的'xdist'插件并使用'py.test -n 4'启动测试时,py.test正在收集所有测试并随机地在4个工作者之间平衡测试.这导致在'testsuitex.py'模块中每次测试时都会执行'setup_class'方法(这违背了我的目的.我希望每个类只执行一次setup_class,然后在那里连续执行测试).

基本上我想要的执行看起来像是:

worker1: executes all …

python pytest xdist

29
推荐指数
3
解决办法
7253
查看次数

dstat cpu输出中的'hiq'和'siq'字段是什么?

dstat CPU指标有两个名为hiq和的字段siq.这些字段代表什么?它们是某种硬件中断和软件中断吗?

metrics

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

标签 统计

pytest ×2

python ×2

logging ×1

metrics ×1

xdist ×1