0

how to writing unit tests for exception and raise? For example I have

someFoo.py


class MyExc(Exception):
  """
  my exc
  """
  pass

def foo(a,b,c):
  raise MyExc

def foo1(a,b):
  assert a==b, 'a==b!!'


tests.py

from someFoo import foo,foo1
import unittest
class Test(unittest.TestCase):
  pass


and I can't find good solution for this

3
  • Please update your question with the not good solutions you found, plus the reasons they are not good. Commented May 3, 2022 at 11:37
  • Also, raise a==b, 'a==b!!' will give you the error TypeError: exceptions must derive from BaseException, so you probably don't want to do that. You can't use any object with raise; it has to be an exception object. Commented May 3, 2022 at 11:45
  • sorry my bad in the second example of course assert Commented May 3, 2022 at 12:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.