-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
77 lines (58 loc) · 1.72 KB
/
Copy pathconftest.py
File metadata and controls
77 lines (58 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Pytest configuration and fixtures for pgsql-test.
This module provides reusable fixtures for testing the pgsql-test framework itself.
"""
import os
from pathlib import Path
import pytest
from pgsql_test import get_connections
from pgsql_test.types import PgConfig
def get_test_pg_config() -> PgConfig:
"""Get PostgreSQL configuration for tests."""
return {
"host": os.environ.get("PGHOST", "localhost"),
"port": int(os.environ.get("PGPORT", "5432")),
"database": os.environ.get("PGDATABASE", "postgres"),
"user": os.environ.get("PGUSER", "postgres"),
"password": os.environ.get("PGPASSWORD", ""),
}
@pytest.fixture
def pg_config() -> PgConfig:
"""Fixture providing PostgreSQL configuration."""
return get_test_pg_config()
@pytest.fixture
def db_connection():
"""
Fixture providing a database connection with automatic teardown.
Usage:
def test_something(db_connection):
conn = db_connection
result = conn.db.query('SELECT 1')
"""
conn = get_connections()
yield conn
conn.teardown()
@pytest.fixture
def db(db_connection):
"""
Fixture providing just the db client with per-test isolation.
Usage:
def test_something(db):
db.before_each()
result = db.query('SELECT 1')
db.after_each()
"""
return db_connection.db
@pytest.fixture
def pg(db_connection):
"""
Fixture providing the superuser pg client.
Usage:
def test_something(pg):
result = pg.query('SELECT 1')
"""
return db_connection.pg
@pytest.fixture
def sql_dir() -> Path:
"""Fixture providing path to test SQL files."""
return Path(__file__).parent / "sql"