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

Piter
  • 61
  • 1
  • 4
  • Please update your question with the not good solutions you found, plus the reasons they are not good. – quamrana May 03 '22 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. – Jack Taylor May 03 '22 at 11:45
  • sorry my bad in the second example of course ```assert ``` – Piter May 03 '22 at 12:01

0 Answers0