\ o / I've nearly monorepod enough libraries to de...
# general
\ o / I've nearly monorepod enough libraries to deploy a service. But the "db library" (read: pile of unnecessary garbage gluing sqlalchemy into... nothing?) doesn't do database isolation very well and as such all the tests fail when run in parallel 😂 SO CLOSE.
note that there is one helper for the concurrent access usecase: https://www.pantsbuild.org/docs/reference-pytest#section-execution-slot-var
it allows tests to ask for an environment variable that gives them a unique (at any given time) slot number
so if you have 8 cores, you’d get slots 1-8, and could have 8 unique databases/tables/etc
I've gone for maximum jank.
Copy code
cur.execute(f"CREATE DATABASE {random_db_name}")
yield random_db_name
        SELECT pg_terminate_backend(pg_stat_activity.pid)
        FROM pg_stat_activity
        WHERE pg_stat_activity.datname = '{random_db_name}'
        AND pid <> pg_backend_pid();""")
    cur.execute(f"DROP DATABASE {random_db_name};")