File tree Expand file tree Collapse file tree 3 files changed +21
-15
lines changed
Expand file tree Collapse file tree 3 files changed +21
-15
lines changed Original file line number Diff line number Diff line change 11from dataclasses import dataclass , field
2- import sys
32from typing import Any
43
54from omnipy .api .enums import EngineChoice
2423from omnipy .hub .root_log import RootLogConfigEntryPublisher , RootLogObjects
2524from omnipy .log .registry import RunStateRegistry
2625from omnipy .modules .prefect .engine .prefect import PrefectEngine
26+ from omnipy .util .helpers import called_from_omnipy_tests
2727
2828
2929def _job_creator_factory ():
@@ -116,16 +116,4 @@ def _update_job_creator_engine(self, _item_changed: Any):
116116 self .objects .job_creator .set_engine (self ._get_engine (self .config .engine ))
117117
118118
119- # TODO: The check disabling runtime for tests also trigger for tests that are run outside of Omnipy,
120- # breaking tests on the user side.
121- # Find a better way to disable the global runtime object for Omnipy tests
122-
123-
124- def _get_runtime () -> 'Runtime | None' :
125- if 'pytest' not in sys .modules :
126- return Runtime ()
127- else :
128- return None
129-
130-
131- runtime : 'Runtime | None' = _get_runtime ()
119+ runtime : 'Runtime | None' = None if called_from_omnipy_tests () else Runtime ()
Original file line number Diff line number Diff line change @@ -249,3 +249,16 @@ def get_calling_module_name() -> str | None:
249249 if module is not None :
250250 return module .__name__
251251 start_frame_index += 1
252+
253+
254+ def called_from_omnipy_tests () -> bool :
255+ stack = inspect .stack ()
256+ for index in range (len (stack )):
257+ frame = stack [index ][0 ]
258+ module = inspect .getmodule (frame )
259+ if module is not None \
260+ and module .__name__ .startswith ('tests' ) \
261+ and module .__file__ is not None \
262+ and 'omnipy/tests' in module .__file__ :
263+ return True
264+ return False
Original file line number Diff line number Diff line change 88from typing_inspect import get_generic_type
99
1010from omnipy import Dataset , Model
11- from omnipy .util .helpers import (ensure_non_str_byte_iterable ,
11+ from omnipy .util .helpers import (called_from_omnipy_tests ,
12+ ensure_non_str_byte_iterable ,
1213 ensure_plain_type ,
1314 get_calling_module_name ,
1415 get_first_item ,
@@ -414,3 +415,7 @@ def local_call_get_calling_module_name() -> str:
414415 assert other_module_call_get_calling_module_name () == 'tests.util.test_helpers'
415416 assert calling_module_name_when_importing_other_module == 'tests.util.test_helpers'
416417
418+
419+ def test_called_from_omnipy_tests () -> None :
420+ # Negative test is left as an exercise to the reader
421+ assert called_from_omnipy_tests ()
You can’t perform that action at this time.
0 commit comments