Search code examples
pythoncelerypython-mock

Why adding arguments to Celery causing error on tests in Python?


I'm trying to test Celery application here's my code

@celery.task(bind=True, default_retry_delay=30)
def convert_video(gif_url, webhook):
    // doing something awesome
       return
    except Exception as exc:
       raise convert_video.retry(exc=exc)

And in my test I have this.

server.convert_video.apply(args=('some_gif', 'http://www.company.com?attachment_id=123')).get()

After I added bind=True, default_retry_delay=30 I get this error

TypeError: convert_video() takes exactly 2 arguments (3 given)


Solution

  • To be honest, I've never used celery, but a quick look at their docs for the bind argument says that:

    The bind argument means that the function will be a “bound method” so that you can access attributes and methods on the task type instance.

    You generally would only use this if this were a method on a class, not a stand-alone function. As a method on a class, its first argument would be self.