fix: properly cleanup env vars with pytest fixtures
This commit is contained in:
parent
5840c0a24b
commit
0be2c3e810
@ -975,17 +975,6 @@ class AppHarnessProd(AppHarness):
|
|||||||
finally:
|
finally:
|
||||||
EnvironmentVariables.REFLEX_SKIP_COMPILE.set(None)
|
EnvironmentVariables.REFLEX_SKIP_COMPILE.set(None)
|
||||||
|
|
||||||
@override
|
|
||||||
def start(self) -> AppHarnessProd:
|
|
||||||
"""Start AppHarnessProd instance.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
self
|
|
||||||
"""
|
|
||||||
EnvironmentVariables.REFLEX_ENV_MODE.set(reflex.constants.base.Env.PROD)
|
|
||||||
_ = super().start()
|
|
||||||
return self
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""Stop the frontend python webserver."""
|
"""Stop the frontend python webserver."""
|
||||||
@ -994,4 +983,3 @@ class AppHarnessProd(AppHarness):
|
|||||||
self.frontend_server.shutdown()
|
self.frontend_server.shutdown()
|
||||||
if self.frontend_thread is not None:
|
if self.frontend_thread is not None:
|
||||||
self.frontend_thread.join()
|
self.frontend_thread.join()
|
||||||
EnvironmentVariables.REFLEX_ENV_MODE.set(None)
|
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Type
|
from typing import Generator, Type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import reflex.constants
|
import reflex.constants
|
||||||
from reflex.config import EnvironmentVariables
|
from reflex.config import EnvironmentVariables
|
||||||
|
from reflex.constants.base import Env
|
||||||
from reflex.testing import AppHarness, AppHarnessProd
|
from reflex.testing import AppHarness, AppHarnessProd
|
||||||
|
|
||||||
DISPLAY = None
|
DISPLAY = None
|
||||||
@ -81,14 +82,18 @@ def pytest_exception_interact(node, call, report):
|
|||||||
)
|
)
|
||||||
def app_harness_env(
|
def app_harness_env(
|
||||||
request: pytest.FixtureRequest,
|
request: pytest.FixtureRequest,
|
||||||
) -> Type[AppHarness]:
|
) -> Generator[Type[AppHarness], None, None]:
|
||||||
"""Parametrize the AppHarness class to use for the test, either dev or prod.
|
"""Parametrize the AppHarness class to use for the test, either dev or prod.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request: The pytest fixture request object.
|
request: The pytest fixture request object.
|
||||||
|
|
||||||
Returns:
|
Yields:
|
||||||
The AppHarness class to use for the test.
|
The AppHarness class to use for the test.
|
||||||
"""
|
"""
|
||||||
harness: Type[AppHarness] = request.param
|
harness: Type[AppHarness] = request.param
|
||||||
return harness
|
if issubclass(harness, AppHarnessProd):
|
||||||
|
EnvironmentVariables.REFLEX_ENV_MODE.set(Env.PROD)
|
||||||
|
yield harness
|
||||||
|
if isinstance(harness, AppHarnessProd):
|
||||||
|
EnvironmentVariables.REFLEX_ENV_MODE.set(None)
|
||||||
|
Loading…
Reference in New Issue
Block a user