adds warning message when super().__init__() is not called at the start of the constructor

This commit is contained in:
Mose Müller
2023-12-06 08:42:48 +01:00
parent e8a0a7c000
commit a97a55712e
3 changed files with 34 additions and 5 deletions

View File

@ -13,6 +13,20 @@ class MyObserver(Observer):
logger.info("'%s' changed to '%s'", full_access_path, value)
def test_constructor_error_message(caplog: pytest.LogCaptureFixture) -> None:
class MyObservable(Observable):
def __init__(self) -> None:
self.attr = 1
super().__init__()
MyObservable()
assert (
"Ensure that super().__init__() is called at the start of the 'MyObservable' "
"constructor! Failing to do so may lead to unexpected behavior." in caplog.text
)
def test_simple_class_attribute(caplog: pytest.LogCaptureFixture) -> None:
class MyObservable(Observable):
int_attribute = 10