Python multiprocessing: AttributeError: Can't pickle local object

Viewed 714

I wrote a ChatOps bot for the collaboration tool Mattermost using this framework. Now I'm trying to write and run integration tests and I used their examples. By cloning the git repository you can run the tests by yourself. Their docker-compose.yml file will only work on a Linux machine. If you want to reproduce it on a Mac machine, you'll have to edit the docker-compose.yml to:

version: "3.7"

services:
  app:
    container_name: "mattermost-bot-test"
    build: .
    command: ./mm/docker-entry.sh
    ports:
      - "8065:8065"
    extra_hosts:
      - "dockerhost:127.0.0.1"

After running the command docker-compose up -d Mattermost is available at localhost:8065. I only took one simple test from their project and copied it in base-test.py. You can see my source code here. After starting the test by running the command pytest --capture=no --log-cli-level=DEBUG . it will return the following error: AttributeError: Can't pickle local object 'start_bot.<locals>.run_bot'. This error also shows up on the same test case in their project. The error happens at line 92 in the utils.py file

What am I doing wrong here?

2 Answers

I don't know if you already went down this road but I think you might get past the pickling error by making run_bot take the bot that it does bot.run() with as an argument and then pass it to the process.

Related