conftest.py 2.3 KB

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