diff --git a/normandy/base/tests/api/test_api.py b/normandy/base/tests/api/test_api.py index 7034decf9..8173af0c6 100644 --- a/normandy/base/tests/api/test_api.py +++ b/normandy/base/tests/api/test_api.py @@ -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() diff --git a/normandy/recipes/tests/test_exports.py b/normandy/recipes/tests/test_exports.py index 0ba7da6e8..2e32acb71 100644 --- a/normandy/recipes/tests/test_exports.py +++ b/normandy/recipes/tests/test_exports.py @@ -48,13 +48,13 @@ 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" @@ -62,7 +62,7 @@ def test_it_checks_config(self, settings): 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" @@ -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. @@ -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}/", @@ -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, @@ -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}/", diff --git a/normandy/recipes/tests/test_signing.py b/normandy/recipes/tests/test_signing.py index 2994193b0..937ebac60 100644 --- a/normandy/recipes/tests/test_signing.py +++ b/normandy/recipes/tests/test_signing.py @@ -34,7 +34,7 @@ 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" @@ -42,7 +42,7 @@ 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_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" @@ -50,7 +50,7 @@ def test_it_checks_settings(self, settings): 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" @@ -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): @@ -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) diff --git a/normandy/recipes/tests/test_utils.py b/normandy/recipes/tests/test_utils.py index 2327c95e1..cd3b4b6cb 100644 --- a/normandy/recipes/tests/test_utils.py +++ b/normandy/recipes/tests/test_utils.py @@ -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):