I'm just a beginner in Python and programming in general, and have some questions about the unittest module.
I have a class, and in the __init__
method I am doing some assertions to check for bad arguments. I would like to create a unittest which checks for such AssertionError when creating new instances.
In the unittest module, one can test (with assertRaises
) for specific exception when a callable is called, but obviously that will apply to methods of the class. What is the proper way to run such test for the constructor?
I know that I can just try to create an instance of the class with bad arguments, and unittest will report a test failure, but that stops immediately after the first such exception, and even if I can wrap multiple tests in multiple test functions, it just doesn't seem elegant at all.