Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

# coding=utf-8 

import pytest 

def whatever(): 

return 9/0 

def test_whatever(): 



except ZeroDivisionError as exc:, pytrace=True)

How to make pytest print traceback, so I would see where in the whatever function an exception was raised?

1 Answer

0 votes
by (106k points)

To properly assert that an exception gets raised in pytest you can use the below-mentioned code:-

def test_raises():

with pytest.raises(Exception) as excinfo: 

raise Exception('some info') 

assert execinfo.value.args[0] == 'some info' 

assert str(execinfo.value) == 'some info'

Related questions

Browse Categories