Skip to content

Commit

Permalink
fix: env var
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Sep 26, 2024
1 parent ca26b0f commit c72a82b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/tests/executor/test_executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import os
import time
import uuid
from collections.abc import Awaitable
from itertools import product
from typing import Any
Expand All @@ -9,7 +11,7 @@
import pytest

from tests.executor.base import BaseExecutorTest
from timeout_executor import AsyncResult
from timeout_executor import AsyncResult, TimeoutExecutor

TEST_SIZE = 3

Expand Down Expand Up @@ -156,3 +158,16 @@ def awaitable_func() -> Awaitable[Any]:
result = await result.delay()
assert isinstance(result, str)
assert result == expect


def test_environment_variable():
key, value = "E" + uuid.uuid4().hex.upper(), str(uuid.uuid4())
os.environ[key] = value

def func() -> bool:
import os

return os.environ.get(key) == value

result = TimeoutExecutor(1).apply(func)
assert result.result() is True
4 changes: 3 additions & 1 deletion src/timeout_executor/executor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import shlex
import subprocess
import sys
Expand Down Expand Up @@ -135,7 +136,8 @@ def _create_process(
logger.debug("%r before create new process", self, stacklevel=stacklevel)
process = subprocess.Popen( # noqa: S603
command,
env={
env=os.environ
| {
TIMEOUT_EXECUTOR_INPUT_FILE: str(input_file),
TIMEOUT_EXECUTOR_INIT_FILE: "" if init_file is None else str(init_file),
},
Expand Down

0 comments on commit c72a82b

Please sign in to comment.