From 6ca8c77b33bd5c42cc2e1295309dbe307b04f5b4 Mon Sep 17 00:00:00 2001 From: Ryan Soley Date: Mon, 12 Aug 2024 13:38:21 -0400 Subject: [PATCH] parametrize test and test warning --- rubicon_ml/domain/project.py | 2 +- tests/unit/domain/test_domain.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rubicon_ml/domain/project.py b/rubicon_ml/domain/project.py index cecd0a35..528aa0f8 100644 --- a/rubicon_ml/domain/project.py +++ b/rubicon_ml/domain/project.py @@ -74,7 +74,7 @@ def __init__( self.id = str(uuid.uuid4()) if kwargs: # replaces `dataclass` behavior of erroring on unexpected kwargs - LOGGER.warn( + LOGGER.warning( f"{self.__class__.__name__}.__init__() got an unexpected keyword " f"argument(s): `{'`, `'.join([key for key in kwargs])}`" ) diff --git a/tests/unit/domain/test_domain.py b/tests/unit/domain/test_domain.py index ed442695..ba3a086f 100644 --- a/tests/unit/domain/test_domain.py +++ b/tests/unit/domain/test_domain.py @@ -1,3 +1,5 @@ +from unittest import mock + import pytest from rubicon_ml.domain.project import Project @@ -8,9 +10,15 @@ [(Project, {"name": "test_domain_extra_kwargs"})], ) def test_domain_extra_kwargs(domain_cls, required_kwargs): - domain = domain_cls(extra="extra", **required_kwargs) + with mock.patch( + f"rubicon_ml.domain.{domain_cls.__name__.lower()}.LOGGER.warning" + ) as logger_warning: + domain = domain_cls(extra="extra", **required_kwargs) - assert "extra" not in domain.__dict__ + logger_warning.assert_called_once_with( + f"{domain_cls.__name__}.__init__() got an unexpected keyword argument(s): `extra`", + ) + assert "extra" not in domain.__dict__ for key, value in required_kwargs.items(): assert getattr(domain, key) == value