def connection(request): """Return a connection to a database""" conn = get_database(":memory:", SCHEMA) def teardown(): print('\n') logger.info('Closing connection') conn.close() logger.debug('Connection closed') request.addfinalizer(teardown) return conn
def init(ctx, db_name, path): """Create a config file for phizz.""" config = ConfigObj() config.filename = config_file database = db_name if os.path.exists(database): logger.error("Databse already exists in {0}".format(database)) sys.exit(1) logger.info("Set database to {0}".format(database)) config["database"] = database config.write() conn = get_database(path_to_database=database, database_schema=schema_path) build_database(conn)
def test_get_database_no_schema(): """docstring for test_database""" #Should provide a schema with pytest.raises(IOError): connection = get_database(":memory:")
def test_get_database(): """docstring for test_database""" connection = get_database(":memory:", SCHEMA) assert connection