1
1
mirror of https://github.com/dbcli/pgcli.git synced 2024-09-17 16:57:39 +03:00
pgcli/tests/conftest.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.1 KiB
Python
Raw Normal View History

import os
import pytest
from utils import (
POSTGRES_HOST,
POSTGRES_PORT,
POSTGRES_USER,
POSTGRES_PASSWORD,
create_db,
db_connection,
drop_tables,
)
2015-01-31 05:59:09 +03:00
import pgcli.pgexecute
@pytest.yield_fixture(scope="function")
def connection():
create_db("_test_db")
connection = db_connection("_test_db")
yield connection
drop_tables(connection)
connection.close()
@pytest.fixture
def cursor(connection):
with connection.cursor() as cur:
return cur
@pytest.fixture
def executor(connection):
return pgcli.pgexecute.PGExecute(
database="_test_db",
user=POSTGRES_USER,
host=POSTGRES_HOST,
password=POSTGRES_PASSWORD,
port=POSTGRES_PORT,
dsn=None,
)
2015-10-22 00:10:30 +03:00
@pytest.fixture
def exception_formatter():
return lambda e: str(e)
@pytest.fixture(scope="session", autouse=True)
def temp_config(tmpdir_factory):
# this function runs on start of test session.
# use temporary directory for config home so user config will not be used
os.environ["XDG_CONFIG_HOME"] = str(tmpdir_factory.mktemp("data"))