Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
add test to call a run_in_venv decorated function within a Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Roulbac committed Aug 2, 2023
1 parent 646a7b9 commit d419d62
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/flojoy_node_venv_test_.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,37 @@ def empty_function_with_error():
# Run the function and expect an error
with pytest.raises(ChildProcessError):
empty_function_with_error()


def test_run_in_venv_runs_within_thread(mock_venv_cache_dir):

from threading import Thread
from queue import Queue

def function_to_run_within_thread(queue):

from flojoy import run_in_venv

@run_in_venv(
pip_dependencies=["numpy==1.23.0"]
)
def func_with_venv():
import numpy as np

return 42

# Run the function
queue.put(func_with_venv())

# Run the function in a thread
queue = Queue()
thread = Thread(target=function_to_run_within_thread, args=(queue,))
thread.start()
thread.join()
# Check that the thread has finished
assert not thread.is_alive()
# Check that there is something in the queue
assert not queue.empty()
# Check that the function has returned
assert queue.get(timeout=60) == 42

0 comments on commit d419d62

Please sign in to comment.