1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] unable to raising exception part of unit test case for a function call, with in the...

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024 às 22:22.

  1. Stack

    Stack Membro Participativo

    I am trying to validate a test case exception raises condition but failing with "AssertionError: Exception not raised"

    Main Module with a function to test

    sample_module

    from xyz import AbcClass

    abc_class = AbcClass()

    def func1():
    #few_steps
    abc_class.do_something()
    #few more steps


    Test class

    class TestClass(unittest.TestCase):

    doo something …
    sys.modules[‘xzy’] = MagicMock()

    def test_func1():
    do something …
    with self.assertRaises(Exception):
    with patch ("xyz.AbcClass”) as mock:
    instance = mock.return_value
    instance.do_something.side_effect = Exception
    from src import sample_module
    sample_module.func1()


    Failure Log

    with self.assertRaises(Exception):
    E AssertionError: Exception not raised

    test_sample_module.py:125: AssertionError

    Continue reading...

Compartilhe esta Página