1
0

conftest.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """Shared conftest for all integration tests."""
  2. import os
  3. import pytest
  4. import reflex.app
  5. from reflex.config import environment
  6. from reflex.testing import AppHarness, AppHarnessProd
  7. DISPLAY = None
  8. XVFB_DIMENSIONS = (800, 600)
  9. @pytest.fixture(scope="session", autouse=True)
  10. def xvfb():
  11. """Create virtual X display.
  12. This function is a no-op unless GITHUB_ACTIONS is set in the environment.
  13. Yields:
  14. the pyvirtualdisplay object that the browser will be open on
  15. """
  16. if os.environ.get("GITHUB_ACTIONS") and not environment.APP_HARNESS_HEADLESS.get():
  17. from pyvirtualdisplay.smartdisplay import ( # pyright: ignore [reportMissingImports]
  18. SmartDisplay,
  19. )
  20. global DISPLAY
  21. with SmartDisplay(visible=False, size=XVFB_DIMENSIONS) as DISPLAY:
  22. yield DISPLAY
  23. DISPLAY = None
  24. else:
  25. yield None
  26. @pytest.fixture(
  27. scope="session", params=[AppHarness, AppHarnessProd], ids=["dev", "prod"]
  28. )
  29. def app_harness_env(request):
  30. """Parametrize the AppHarness class to use for the test, either dev or prod.
  31. Args:
  32. request: The pytest fixture request object.
  33. Returns:
  34. The AppHarness class to use for the test.
  35. """
  36. return request.param
  37. @pytest.fixture(autouse=True)
  38. def raise_console_error(request, mocker):
  39. """Spy on calls to `console.error` used by the framework.
  40. Help catch spurious error conditions that might otherwise go unnoticed.
  41. If a test is marked with `ignore_console_error`, the spy will be ignored
  42. after the test.
  43. Args:
  44. request: The pytest request object.
  45. mocker: The pytest mocker object.
  46. Yields:
  47. control to the test function.
  48. """
  49. spy = mocker.spy(reflex.app.console, "error")
  50. yield
  51. if "ignore_console_error" not in request.keywords:
  52. spy.assert_not_called()