conftest.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from __future__ import absolute_import, print_function
  2. import os
  3. import subprocess
  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 on Travis CI (see: https://docs.travis-ci.com/user/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: B314
  24. u"""
  25. ###################
  26. #
  27. # Frontend assets last built {} seconds ago, skipping rebuilds for another {} seconds.
  28. # Delete the file: `.webpack.meta` to rebuild.
  29. #
  30. ###################
  31. """.format(
  32. last_built, 3600 - last_built
  33. )
  34. )
  35. return
  36. except IOError:
  37. pass
  38. except Exception:
  39. pass
  40. print( # noqa: B314
  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. )