Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Prevent failures when _metadata attribute is missing (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Mar 25, 2022
1 parent cac42ce commit 22e5186
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/pytest_molecule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,23 @@ def pytest_configure(config):
]

# Add extra information that may be key for debugging failures
for package in ["molecule"]:
config._metadata["Packages"][package] = pkg_resources.get_distribution(
package
).version

if "Tools" not in config._metadata:
config._metadata["Tools"] = {}
config._metadata["Tools"]["ansible"] = str(ansible_version())

# Adds interesting env vars
env = ""
for key, value in sorted(os.environ.items()):
for var_name in interesting_env_vars:
if key.startswith(var_name):
env += f"{key}={value} "
config._metadata["env"] = env
if hasattr(config, "_metadata"):
for package in ["molecule"]:
config._metadata["Packages"][package] = pkg_resources.get_distribution(
package
).version

if "Tools" not in config._metadata:
config._metadata["Tools"] = {}
config._metadata["Tools"]["ansible"] = str(ansible_version())

# Adds interesting env vars
env = ""
for key, value in sorted(os.environ.items()):
for var_name in interesting_env_vars:
if key.startswith(var_name):
env += f"{key}={value} "
config._metadata["env"] = env

# We hide DeprecationWarnings thrown by driver loading because these are
# outside our control and worse: they are displayed even on projects that
Expand Down

0 comments on commit 22e5186

Please sign in to comment.