Skip to content

Commit

Permalink
Change exception message checking to match pytest 5.
Browse files Browse the repository at this point in the history
From [the pytest changelog](https://docs.pytest.org/en/latest/changelog.html#pytest-5-0-0-2019-06-28):

> ExceptionInfo objects (returned by pytest.raises) now have the same str representation as repr, which avoids some confusion when users use print(e) to inspect the object.
  • Loading branch information
mythmon committed Aug 8, 2019
1 parent 6dcdf23 commit a9a0682
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion normandy/base/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_register_view_requires_name(self):
router = MixedViewRouter()
with pytest.raises(TypeError) as err:
router.register_view("view", View, allow_cdn=True)
assert "missing 1 required keyword-only argument: 'name'" in str(err)
assert "missing 1 required keyword-only argument: 'name'" in str(err.value)

def test_get_urls_includes_non_viewset_views(self):
router = MixedViewRouter()
Expand Down
14 changes: 7 additions & 7 deletions normandy/recipes/tests/test_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ def test_it_checks_config(self, settings):
settings.REMOTE_SETTINGS_PASSWORD = "p4ssw0rd"
with pytest.raises(ImproperlyConfigured) as exc:
exports.RemoteSettings().check_config()
assert "REMOTE_SETTINGS_USERNAME" in str(exc)
assert "REMOTE_SETTINGS_USERNAME" in str(exc.value)

# Set empty USERNAME
settings.REMOTE_SETTINGS_USERNAME = ""
with pytest.raises(ImproperlyConfigured) as exc:
exports.RemoteSettings().check_config()
assert "REMOTE_SETTINGS_USERNAME" in str(exc)
assert "REMOTE_SETTINGS_USERNAME" in str(exc.value)

# Leave out PASSWORD
settings.REMOTE_SETTINGS_URL = "http://some-server/v1"
settings.REMOTE_SETTINGS_USERNAME = "usename"
settings.REMOTE_SETTINGS_PASSWORD = None
with pytest.raises(ImproperlyConfigured) as exc:
exports.RemoteSettings().check_config()
assert "REMOTE_SETTINGS_PASSWORD" in str(exc)
assert "REMOTE_SETTINGS_PASSWORD" in str(exc.value)

# Leave out COLLECTION_ID
settings.REMOTE_SETTINGS_URL = "http://some-server/v1"
Expand All @@ -71,7 +71,7 @@ def test_it_checks_config(self, settings):
settings.REMOTE_SETTINGS_COLLECTION_ID = None
with pytest.raises(ImproperlyConfigured) as exc:
exports.RemoteSettings().check_config()
assert "REMOTE_SETTINGS_COLLECTION_ID" in str(exc)
assert "REMOTE_SETTINGS_COLLECTION_ID" in str(exc.value)

def test_check_connection(self, rs_settings, requestsmock):
# Root URL should return currently authenticated user.
Expand All @@ -80,7 +80,7 @@ def test_check_connection(self, rs_settings, requestsmock):

with pytest.raises(ImproperlyConfigured) as exc:
exports.RemoteSettings().check_config()
assert "Invalid Remote Settings credentials" in str(exc)
assert "Invalid Remote Settings credentials" in str(exc.value)

requestsmock.get(
f"{rs_settings.REMOTE_SETTINGS_URL}/",
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_check_connection(self, rs_settings, requestsmock):
assert (
f"Remote Settings collection {rs_settings.REMOTE_SETTINGS_COLLECTION_ID} "
"is not writable"
) in str(exc)
) in str(exc.value)

requestsmock.get(
collection_url,
Expand All @@ -128,7 +128,7 @@ def test_check_connection(self, rs_settings, requestsmock):
assert (
"Review was not disabled on Remote Settings collection "
f"{rs_settings.REMOTE_SETTINGS_COLLECTION_ID}."
) in str(exc)
) in str(exc.value)

requestsmock.get(
f"{rs_settings.REMOTE_SETTINGS_URL}/",
Expand Down
14 changes: 7 additions & 7 deletions normandy/recipes/tests/test_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ def test_it_checks_settings(self, settings):
settings.AUTOGRAPH_HAWK_SECRET_KEY = "hawk secret key"
with pytest.raises(ImproperlyConfigured) as exc:
signing.Autographer()
assert "AUTOGRAPH_URL" in str(exc)
assert "AUTOGRAPH_URL" in str(exc.value)

# Leave out HAWK_ID
settings.AUTOGRAPH_URL = "https://autograph.example.com"
settings.AUTOGRAPH_HAWK_ID = None
settings.AUTOGRAPH_HAWK_SECRET_KEY = "hawk secret key"
with pytest.raises(ImproperlyConfigured) as exc:
signing.Autographer()
assert "AUTOGRAPH_HAWK_ID" in str(exc)
assert "AUTOGRAPH_HAWK_ID" in str(exc.value)

# Leave out HAWK_SECRET_KEY
settings.AUTOGRAPH_URL = "https://autograph.example.com"
settings.AUTOGRAPH_HAWK_ID = "hawk id"
settings.AUTOGRAPH_HAWK_SECRET_KEY = None
with pytest.raises(ImproperlyConfigured) as exc:
signing.Autographer()
assert "AUTOGRAPH_HAWK_SECRET_KEY" in str(exc)
assert "AUTOGRAPH_HAWK_SECRET_KEY" in str(exc.value)

# Include everything
settings.AUTOGRAPH_URL = "https://autograph.example.com"
Expand Down Expand Up @@ -171,13 +171,13 @@ def test_incomplete_cert(self):
bad_data = "-----BEGIN CERTIFICATE-----\nMIIGXTCCBEWgAwIBAgIEAQAACjANBgkq"
with pytest.raises(signing.CertificateParseError) as exc:
signing.extract_certs_from_pem(bad_data)
assert "Unexpected end of input." in str(exc)
assert "Unexpected end of input." in str(exc.value)

def test_not_a_cert(self):
bad_data = "hello world"
with pytest.raises(signing.CertificateParseError) as exc:
signing.extract_certs_from_pem(bad_data)
assert 'Unexpected input "hello world"' in str(exc)
assert 'Unexpected input "hello world"' in str(exc.value)


class TestParseCertsFromDer(object):
Expand Down Expand Up @@ -391,5 +391,5 @@ def test_it_reads_general_time_format(self):
def test_it_errors_on_unsupported_formats(self):
with pytest.raises(signing.BadCertificate) as exc:
signing.read_timestamp_object({"unsupportedTimestamp": b"gibberish"})
assert "Timestamp not in expected format" in str(exc)
assert "unsupportedTimestamp" in str(exc)
assert "Timestamp not in expected format" in str(exc.value)
assert "unsupportedTimestamp" in str(exc.value)
4 changes: 2 additions & 2 deletions normandy/recipes/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def test_error_cases(self, bad_val):
fraction_to_key(bad_val)

# Check that it is the expected error, not some spurious error from elsewhere.
assert "must be between 0 and 1 inclusive" in str(exc)
assert "must be between 0 and 1 inclusive" in str(exc.value)
# Check that the bad value is mentioned
assert str(bad_val) in str(exc)
assert str(bad_val) in str(exc.value)

def test_result_length(self):
for _ in range(100):
Expand Down

0 comments on commit a9a0682

Please sign in to comment.