Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from Kroisse/master
Browse files Browse the repository at this point in the history
Fail the testing fast when the Redis server is unreachable
  • Loading branch information
dahlia committed Mar 10, 2013
2 parents ba26d21 + 7ede2e0 commit 868e121
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions sidertests/env.py
@@ -1,7 +1,7 @@
import os
import datetime
import pytest
from redis.client import StrictRedis
from redis.client import StrictRedis, ConnectionError
from sider.session import Session
from sider.types import Integer

Expand All @@ -10,11 +10,20 @@ def get_client(cls=StrictRedis):
host = os.environ.get('SIDERTEST_HOST', 'localhost')
port = int(os.environ.get('SIDERTEST_PORT', 6379))
db = int(os.environ.get('SIDERTEST_DB', 0))
return cls(host=host, port=port, db=db)
try:
client = cls(host=host, port=port, db=db)
# To connect on the server forcibly,
# send a ping explicitly at this line.
client.ping()
return client
except ConnectionError as e:
pytest.fail(str(e), pytrace=False)


def get_session():
session = Session(get_client())
def get_session(client=None):
if client is None:
client = get_client()
session = Session(client)
session.verbose_transaction_error = True
return session

Expand All @@ -30,8 +39,7 @@ def key(key):
@pytest.fixture
def session(request):
client = get_client()
session = Session(client)
session.verbose_transaction_error = True
session = get_session(client)

@request.addfinalizer
def fin():
Expand Down

0 comments on commit 868e121

Please sign in to comment.