- """
- Read in each .yaml or .env file. If it is successfully parsed as yaml, save
- contents, else add filename to list of bad yaml files. Log the result of
- parse attempt.
- """
- conf = YamlLintConfig("rules: {}")
-
- if path.splitext(filename)[-1] in [".yml", ".yaml", ".env"]:
- gen = linter.run(open(filename), conf)
- errors = list(gen)
-
- assert not errors, "Error parsing file {} with error {}".format(
- filename, errors
- )
- else:
- pytest.skip(
- "The file does not have any of the extensions .yml,\
- .yaml, or .env"
- )
+ if path.splitext(filename)[-1].lower() not in (".yml", ".yaml", ".env"):
+ pytest.skip("Not a YAML file")
+ try:
+ load_yaml(filename)
+ except YAMLError as e:
+ assert False, (
+ "Invalid YAML detected: {} "
+ "NOTE: Online YAML checkers such as yamllint.com "
+ "can helpful in diagnosing errors in YAML"
+ ).format(str(e).replace("\n", " "))