Skip to content

Commit 9a6616d

Browse files
committed
Refactor test cases
1 parent 7b21b19 commit 9a6616d

5 files changed

Lines changed: 305 additions & 419 deletions

File tree

tests/conftest.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
4+
import pytest
5+
6+
from pymongosql.connection import Connection
7+
8+
# Centralized test configuration sourced from environment to allow running tests
9+
# against remote MongoDB (e.g. Atlas) or local test instance.
10+
TEST_URI = os.environ.get("PYMONGOSQL_TEST_URI") or os.environ.get("MONGODB_URI")
11+
TEST_DB = os.environ.get("PYMONGOSQL_TEST_DB", "test_db")
12+
13+
14+
def make_conn(**kwargs):
15+
"""Create a Connection using TEST_URI if provided, otherwise use a local default."""
16+
if TEST_URI:
17+
if "database" not in kwargs:
18+
kwargs["database"] = TEST_DB
19+
return Connection(host=TEST_URI, **kwargs)
20+
21+
# Default local connection parameters
22+
defaults = {"host": "mongodb://testuser:testpass@localhost:27017/test_db?authSource=test_db", "database": "test_db"}
23+
for k, v in defaults.items():
24+
kwargs.setdefault(k, v)
25+
return Connection(**kwargs)
26+
27+
28+
@pytest.fixture
29+
def conn():
30+
"""Yield a Connection instance configured via environment variables and tear it down after use."""
31+
connection = make_conn()
32+
try:
33+
yield connection
34+
finally:
35+
try:
36+
connection.close()
37+
except Exception:
38+
pass
39+
40+
41+
@pytest.fixture
42+
def make_connection():
43+
"""Provide the helper make_conn function to tests that need to create connections with custom args."""
44+
return make_conn

tests/session_test_summary.md

Lines changed: 0 additions & 201 deletions
This file was deleted.

0 commit comments

Comments
 (0)