Skip to content

anna-money/pytest-pg

Repository files navigation

To speed up tests, pytest-pg does the following tweaks:

  1. fsync=off
  2. full_page_writes=off
  3. synchronous_commit=off
  4. jit=off
  5. bgwriter_lru_maxpages=0
  6. data directory is mounted to a tmpfs

How to use?

import asyncpg


async def test_asyncpg_query(pg):
    conn = await asyncpg.connect(
        user=pg.user,
        password=pg.password,
        database=pg.database,
        host=pg.host,
        port=pg.port,
    )

    await conn.execute("CREATE TABLE test_table (id serial PRIMARY KEY, value text);")
    await conn.execute("INSERT INTO test_table (value) VALUES ($1)", "hello")
    row = await conn.fetchrow("SELECT value FROM test_table WHERE id = $1", 1)

    assert row["value"] == "hello"

    await conn.close()

About

A tiny plugin for pytest which runs PostgreSQL in Docker

Resources

License

Stars

Watchers

Forks

Contributors 7