conftest.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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", "--silent", "webpack"],
  52. env={
  53. "NODE_ENV": "development",
  54. "PATH": os.environ["PATH"],
  55. "NODE_OPTIONS": "--max-old-space-size=4096",
  56. },
  57. )
  58. if status != 0:
  59. raise Exception(
  60. "Unable to run `webpack` -- make sure your development environment is setup correctly: https://docs.sentry.io/development/contribute/environment/#macos---nodejs"
  61. )
  62. except OSError:
  63. raise Exception(
  64. "Unable to run `yarn` -- make sure your development environment is setup correctly: https://docs.sentry.io/development/contribute/environment/#macos---nodejs"
  65. )