在pytest中运行测试用例时如何显示断点而不是断言错误

时间:2019-04-26 05:46:18

标签: python python-3.x pytest

我正在使用pytest验证数据库数据。我正在生成一个显示测试用例结果的html报告,对于失败的案例,它仅显示断言错误,但是我需要测试用例失败的断点。有人能帮忙吗?

Main_methods.py

import pymongo
import re
import unittest
import pytest



class Main_methods():     

    def minlength(self,data,category_name,min_length):
       ''' validate the minimum length condition by comparing with db data for a given category

            Parameter: Db data, category name, minium length '''
       for name in data:            
           len(name[category_name])>=min_length

test_case.py

mport pymongo
import re
import unittest
import pytest
from main_method import Main_methods

class_object=Main_methods()

@pytest.fixture
def data():
    '''Initialise the variable for all the methods using this method and returns the value after the yield keyword.'''
    myclient = pymongo.MongoClient("mongodb://root:mongodbadmin@18.223.241.113:27017")
    mydb = myclient["Ecomm_Product_db"]
    mycol = mydb["products"]
    yield mycol.find({})
class Test_Category_Name(): 

    def test_minlength(self,data):
        assert class_object.minlength(data,'category',5)

实际结果

    def test_minlength(self,data):
>       assert class_object.minlength(data,'category',5)
E       AssertionError: assert None
E        +  where None = <bound method Main_methods.minlength of <main_method.Main_methods object at 0x0326B670>>(<pymongo.cursor.Cursor object at 0x0346A230>, 'category', 5)
E        +    where <bound method Main_methods.minlength of <main_method.Main_methods object at 0x0326B670>> = <main_method.Main_methods object at 0x0326B670>.minlength

testcase.py:20: AssertionError

我需要的结果(预期)

 def test_category_minlength(data):
            '''Asserts given min length condition for category name '''
            for name in data:
>                   assert len(name['category'])>=5
E                   AssertionError: assert 3 >= 5
E                    +  where 3 = len('SSD')


0 个答案:

没有答案