diff --git a/dramatiq/generic.py b/dramatiq/generic.py index a1314cfe..d6df9cb6 100644 --- a/dramatiq/generic.py +++ b/dramatiq/generic.py @@ -105,7 +105,7 @@ def __name__(self): def __call__(self, *args, **kwargs): return self.perform(*args, **kwargs) - def perform(self): + def perform(self, *args, **kwargs): """This is the method that gets called when the actor receives a message. All non-abstract subclasses must implement this method. diff --git a/tests/test_generic_actors.py b/tests/test_generic_actors.py index e59d5651..ff416278 100644 --- a/tests/test_generic_actors.py +++ b/tests/test_generic_actors.py @@ -45,6 +45,30 @@ class Foo(dramatiq.GenericActor): Foo() +def test_generic_actors_raise_not_implemented_if_perform_is_missing_and_called_with_args(stub_broker): + # Reggression test for #805 + # Given that I've subclassed GenericActor without implementing perform + class Foo(dramatiq.GenericActor): + pass + + # When I call that actor with some arguments + # Then a NotImplementedError should be raised + with pytest.raises(NotImplementedError, match=r"Foo does not implement perform\(\)"): + Foo(1, foo="bar") + + +def test_generic_actors_raise_type_error_if_perform_is_called_with_wrong_args(stub_broker): + # Given that I've subclassed GenericActor without implementing perform + class Foo(dramatiq.GenericActor): + def perform(self, foo): + pass + + # When I call that actor with the wrong arguments + # Then a TypeError should be raised + with pytest.raises(TypeError, match=r"\.Foo\.perform\(\) got an unexpected keyword argument 'bar'"): + Foo(bar=2) + + def test_generic_actors_can_be_abstract(stub_broker, stub_worker): # Given that I have a calls database calls = set()