conftest.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import os
  2. import subprocess
  3. import sys
  4. import time
  5. from sentry.utils import json
  6. def pytest_configure(config):
  7. """
  8. Generate frontend assets before running any acceptance tests
  9. TODO: There is a bug if you run `py.test` with `-f` -- the built
  10. assets will trigger another `py.test` run.
  11. """
  12. # Do not build in CI because tests are run w/ `make test-acceptance` which builds assets
  13. # Can also skip with the env var `SKIP_ACCEPTANCE_UI_BUILD`
  14. # `CI` is a default env var in GHA (https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables)
  15. if os.environ.get("CI") or os.environ.get("SKIP_ACCEPTANCE_UI_BUILD"):
  16. return
  17. try:
  18. with open("./.webpack.meta") as f:
  19. data = json.load(f)
  20. # If built within last hour, do not build again
  21. last_built = int(time.time()) - data["built"]
  22. if last_built <= 3600:
  23. print( # noqa: S002
  24. f"""
  25. ###################
  26. #
  27. # Frontend assets last built {last_built} seconds ago, skipping rebuilds for another {3600 - last_built} seconds.
  28. # Delete the file: `.webpack.meta` to rebuild.
  29. #
  30. ###################
  31. """,
  32. file=sys.stderr,
  33. )
  34. return
  35. except OSError:
  36. pass
  37. except Exception:
  38. pass
  39. print( # noqa: S002
  40. """
  41. ###################
  42. #
  43. # Running webpack to compile frontend assets - this will take awhile
  44. #
  45. ###################
  46. """
  47. )
  48. try:
  49. status = subprocess.call(
  50. ["yarn", "build-acceptance"],
  51. env={"PATH": os.environ["PATH"], "NODE_OPTIONS": "--max-old-space-size=4096"},
  52. )
  53. if status != 0:
  54. raise Exception(
  55. "Unable to run `webpack` -- make sure your development environment is setup correctly: https://docs.sentry.io/development/contribute/environment/#macos---nodejs"
  56. )
  57. except OSError:
  58. raise Exception(
  59. "Unable to run `yarn` -- make sure your development environment is setup correctly: https://docs.sentry.io/development/contribute/environment/#macos---nodejs"
  60. )