Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception when missing env var #253

Merged
merged 1 commit into from Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions podman/client.py
Expand Up @@ -113,6 +113,9 @@ def from_env(

Returns:
Client used to communicate with a Podman service.

Raises:
ValueError when required environment variable is not set
"""
environment = environment or os.environ
credstore_env = credstore_env or {}
Expand All @@ -121,6 +124,8 @@ def from_env(
version = None

host = environment.get("CONTAINER_HOST") or environment.get("DOCKER_HOST") or None
if host is None:
raise ValueError("CONTAINER_HOST or DOCKER_HOST must be set to URL of podman service.")

return PodmanClient(
base_url=host,
Expand Down
6 changes: 6 additions & 0 deletions podman/tests/integration/test_system.py
Expand Up @@ -57,3 +57,9 @@ def test_login(self):
)
)
self.assertIn("lookup fake_registry: no such host", e.exception.explanation)

def test_from_env(self):
"""integration: from_env() error message"""
with self.assertRaises(ValueError) as e:
next(self.client.from_env())
self.assertIn("CONTAINER_HOST or DOCKER_HOST", repr(e.exception))