Skip to content

Commit c4b0f8d

Browse files
committed
disable runtime only for omnipy tests, not all tests
1 parent 67f11e6 commit c4b0f8d

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/omnipy/hub/runtime.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from dataclasses import dataclass, field
2-
import sys
32
from typing import Any
43

54
from omnipy.api.enums import EngineChoice
@@ -24,6 +23,7 @@
2423
from omnipy.hub.root_log import RootLogConfigEntryPublisher, RootLogObjects
2524
from omnipy.log.registry import RunStateRegistry
2625
from omnipy.modules.prefect.engine.prefect import PrefectEngine
26+
from omnipy.util.helpers import called_from_omnipy_tests
2727

2828

2929
def _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()

src/omnipy/util/helpers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/util/test_helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from typing_inspect import get_generic_type
99

1010
from 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()

0 commit comments

Comments
 (0)