Commit fdc5c7ca authored by Kevin Morris's avatar Kevin Morris
Browse files

add aurweb.testing, a module with testing utilities

Signed-off-by: Kevin Morris's avatarKevin Morris <>
parent 8e7f1a03
from aurweb.db import get_engine
def setup_test_db(*args):
""" This function is to be used to setup a test database before
using it. It takes a variable number of table strings, and for
each table in that set of table strings, it deletes all records.
The primary goal of this method is to configure empty tables
that tests can use from scratch. This means that tests using
this function should make sure they do not depend on external
records and keep their logic self-contained.
Generally used inside of pytest fixtures, this function
can be used anywhere, but keep in mind its functionality when
doing so.
setup_test_db("Users", "Sessions")
test_tables = ["Users", "Sessions"];
engine = get_engine()
conn = engine.connect()
tables = list(args)
for table in tables:
conn.execute(f"DELETE FROM {table}")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment