How to show the break point instead of assertion error while running the test case in pytest

谁说我不能喝 提交于 2019-12-11 15:05:07

问题


I am using pytest to validate db data. I am generating a html report which shows test case result,For failed case it only shows Assertion error, But i need the break point where the test case fails. Can anyone help with this?

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)

Actual result

    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

Result i need(Expected)

 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')


来源:https://stackoverflow.com/questions/55861456/how-to-show-the-break-point-instead-of-assertion-error-while-running-the-test-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!