Skip to content

Commit

Permalink
Add test to check CfgNotFound exception (#469)
Browse files Browse the repository at this point in the history
* Remove Exception warning if option is set to True too

* Assess Exception not raised

* Second warning is covered anyway
  • Loading branch information
David Bouchare committed Oct 31, 2019
1 parent e6dfe94 commit 6de7f51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datadog/util/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_hostname(hostname_from_config):
hostname = None
config = None

# first, try the config
# first, try the config if hostname_from_config is set to True
try:
if hostname_from_config:
config = get_config()
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
HOST_NAME,
FAKE_PROXY
)
from datadog.util.hostname import CfgNotFound, get_hostname

from tests.util.contextmanagers import EnvVars


Expand Down Expand Up @@ -117,9 +119,15 @@ def test_get_hostname(self, mock_config_path):
initialize()
self.assertEqual(api._host_name, HOST_NAME, api._host_name)

def test_hostname_warning_not_present(self):
try:
get_hostname(hostname_from_config=False)
except CfgNotFound:
pytest.fail("Unexpected CfgNotFound Exception")

def test_errors_suppressed(self):
"""
API `errors` field ApiError supppressed when specified
API `errors` field ApiError suppressed when specified
"""
# Test API, application keys, API host, and some HTTP client options
initialize(api_key=API_KEY, app_key=APP_KEY, api_host=API_HOST)
Expand Down

0 comments on commit 6de7f51

Please sign in to comment.