run-model-tests 822 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. import os
  3. import os.path
  4. import click
  5. from sentry.utils import json
  6. def find_test_cases_matching(model_name: str):
  7. manifest = json.loads(open(os.environ["SENTRY_MODEL_MANIFEST_FILE_PATH"]).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()