run-model-tests 813 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. import os
  3. import os.path
  4. import click
  5. import orjson
  6. def find_test_cases_matching(model_name: str):
  7. manifest = orjson.loads(open(os.environ["SENTRY_MODEL_MANIFEST_FILE_PATH"], "rb").read())
  8. for test_node_id, hits in manifest.items():
  9. if model_name in hits:
  10. yield test_node_id.split("::")[1]
  11. @click.command()
  12. @click.argument("target_model", required=True)
  13. @click.argument("pytest_options", nargs=-1)
  14. def main(target_model: str, pytest_options):
  15. """
  16. Script that uses the SENTRY_MODEL_MANIFEST_FILE_PATH path to execute tests affected by a specific model.
  17. """
  18. os.execvp(
  19. "pytest",
  20. ["pytest", "-k", " or ".join(find_test_cases_matching(target_model))]
  21. + list(pytest_options),
  22. )
  23. if __name__ == "__main__":
  24. main()