Skip to content

Commit

Permalink
Improve base URL verification failure message
Browse files Browse the repository at this point in the history
  • Loading branch information
davehunt committed Aug 13, 2015
1 parent 81f2257 commit 22f0b71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ def base_url(request):

@pytest.fixture(scope='session', autouse=True)
def _verify_base_url(request, base_url):
"""Verify that the base URL is responding with an acceptable status code"""
if base_url:
response = requests.get(base_url, timeout=REQUESTS_TIMEOUT)
if response.status_code not in (200, 401):
ok_codes = (200, 401)
if response.status_code not in ok_codes:
raise pytest.UsageError(
'Base URL did not return status code 200 or 401. '
'(URL: %s, Response: %s, Headers: %s)' % (
base_url, response.status_code, response.headers))
'Base URL did not respond with one of the following status '
'codes: {0}.\nURL: {1},\nResponse status code: {2.status_code}'
'\nResponse headers: {2.headers}'.format(
', '.join(map(str, ok_codes)), base_url, response))


@pytest.fixture
Expand Down
7 changes: 4 additions & 3 deletions testing/test_base_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_pass(_verify_base_url): pass
assert result.ret != 0
# tracestyle is native by default for hook failures
result.stdout.fnmatch_lines([
'*UsageError: Base URL did not return status code '
'200 or 401*Response: {0}, Headers:*{{*}}*'.format(status_code)
])
'*UsageError: Base URL did not respond with one of the following status codes: *.',
'*URL: {0}*'.format(base_url),
'*Response status code: {0}*'.format(status_code),
'*Response headers: {*}*'])

0 comments on commit 22f0b71

Please sign in to comment.