Skip to content

Commit

Permalink
Merge pull request pytest-dev#121 from manahl/xfang-fix-hostname-access
Browse files Browse the repository at this point in the history
fix hostname access
  • Loading branch information
javefang authored Feb 12, 2019
2 parents 9f70582 + 7278fc3 commit 42d7852
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

## Changelog

### 1.6.0 (Unreleased)
### 1.6.1 (Unrelease)
* pytest-server-fixtures: fix exception when attempting to access hostname while server is not started

### 1.6.0 (2019-02-12)
* pytest-server-fixtures: added previously removed TestServerV2.kill() function
* pytest-profiling: pin more-itertools==5.0.0 in integration tests, as that's a PY3 only release

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0
1.6.1
2 changes: 2 additions & 0 deletions pytest-server-fixtures/pytest_server_fixtures/base2.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def hostname(self):
"""
Get the IP address of the server.
"""
if not self._server:
return None
return self._server.hostname

@property
Expand Down
6 changes: 6 additions & 0 deletions pytest-server-fixtures/pytest_server_fixtures/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def check_server_up(self):
import pymongo
from pymongo.errors import AutoReconnect, ConnectionFailure

# Hostname must exist before continuing
# Some server class (e.g. Docker) will only allocate an IP after the
# container has started.
if not self.hostname:
return False

log.info("Connecting to Mongo at %s:%s" % (self.hostname, self.port))
try:
self.api = pymongo.MongoClient(self.hostname, self.port,
Expand Down
10 changes: 7 additions & 3 deletions pytest-server-fixtures/pytest_server_fixtures/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ def port(self):
def check_server_up(self):
""" Ping the server
"""
print("pinging Redis at %s:%s db %s" % (
self.hostname, self.port, self.db
))

if not self.hostname:
return False

try:
print("pinging Redis at %s:%s db %s" % (
self.hostname, self.port, self.db
))
return self.api.ping()
except redis.ConnectionError as e:
print("server not up yet (%s)" % e)
Expand Down
4 changes: 4 additions & 0 deletions pytest-server-fixtures/pytest_server_fixtures/rethink.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ def check_server_up(self):
"""Test connection to the server."""
log.info("Connecting to RethinkDB at {0}:{1}".format(
self.hostname, self.port))

if not self.hostname:
return False

try:
self.conn = rethinkdb.connect(host=self.hostname,
port=self.port, db='test')
Expand Down
4 changes: 4 additions & 0 deletions pytest-server-fixtures/tests/unit/test_server_v2_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ def test_init():
assert ts._cwd == sentinel.cwd
assert ts._server_class == sentinel.server_class

def test_hostname_when_server_is_not_started():
ts = _TestServerV2()
assert ts.hostname == None

0 comments on commit 42d7852

Please sign in to comment.