[py-dev] User defined exception - py.testing
Santosh Philip
santoshphilip at mac.com
Sun Nov 12 06:58:06 CET 2006
I am having some trouble with testing user defined exceptions
==============
this one works
------------
def anexception(arg):
"""just raise an exception with ValueError"""
if arg == 5:
raise ValueError, 'Just a ValueError'
def test_anexception():
"""py.test for anexception"""
import py.test
py.test.raises(ValueError, anexception, 5)
===============
this one does not work
---------------
class MyError(Exception):
"""pass"""
pass
def anotherexception(arg):
"""just raise an exception with ValueError"""
if arg == 5:
raise MyError, 'its a MyError'
def test_anotherexception():
"""py.test for anotherexception"""
import py.test
py.test.raises(ValueError, anotherexception, 5)
================
Are test for user defined exceptions working in py.test
or
Am I doing something wrong ?
when it doesn't work, the output looks like
MacBook:~/Documents/doe2python_DSU santosh$ py.test doesntwork.py
inserting into sys.path:
/Users/santosh/Documents/coolshadowprojects/pydottest/py-dist
============================= test process starts
==============================
testing-mode: inprocess
executable:
/Library/Frameworks/Python.framework/Versions/2.4/Resources/Python.app/
Contents/MacOS/Python (2.4.3-final-0)
using py lib:
/Users/santosh/Documents/coolshadowprojects/pydottest/py-dist/py <rev
31477>
doesntwork.py[1] F
________________________________________________________________________
________
______________________ entrypoint: test_anotherexception
_______________________
def test_anotherexception():
"""py.test for anotherexception"""
import py.test
> py.test.raises(ValueError, anotherexception, 5)
[/Users/santosh/Documents/doe2python_DSU/doesntwork.py:13]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
def anotherexception(arg):
"""just raise an exception with ValueError"""
if arg == 5:
E raise MyError, 'its a MyError'
> MyError: its a MyError
[/Users/santosh/Documents/doe2python_DSU/doesntwork.py:8]
________________________________________________________________________
________
=================== tests finished: 1 failed in 0.02 seconds
===================
thanks
Santosh
More information about the Pytest-dev
mailing list