TypeError: __init__() takes 5 positional arguments error while creating aiopg Pool

142 views Asked by At

I have written the below code for some unit testing. Wondering if someone can point me in the right direction.I know I am missing somthing but cant figure it out.

class testing(tornado.testing.AsyncHTTPTestCase):

    def setUp(self):
        super().setUp()
        loop = asyncio.get_event_loop()
        loop.run_until_complete(self.reset())

    async def reset(self):
        async with self.get_db().acquire() as conn:
            async with conn.cursor() as cur:
                await cur.execute('DELETE FROM vehicles')

    def get_db(self):
        '''
        Instantiate the database.
        '''
        return aiopg.Pool(
            None, 1, 10, None, 5,
            enable_json=True, enable_hstore=True,
            enable_uuid=True, echo=True, on_connect=None,
            pool_recycle=True,
            host='db' if os.getenv('IN_DOCKER') == 'true' \
                else options.db_host,
            port=options.db_port,
            user=options.db_user,
            password=options.db_password,
            dbname=options.db_database
        )

    def get_app(self):
        return Application(self.get_db())

Error:

Traceback (most recent call last):
  File "tests.py", line 33, in setUp
    loop.run_until_complete(self.reset())
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
    return future.result()
  File "tests.py", line 36, in reset
    async with self.get_db().acquire() as conn:
  File "tests.py", line 54, in get_db
    dbname=options.db_database
TypeError: __init__() takes 5 positional arguments but 6 positional arguments (and 6 keyword-only arguments) were given
1

There are 1 answers

2
Talon On BEST ANSWER

aiopg.Pool[1] expects the positional arguments

dsn, minsize, maxsize, timeout

You have given 5 positional arguments

None, 1, 10, None, 5

That's one argument too much.