Skip to content

Commit

Permalink
Fix issue when running demos from within venv.
Browse files Browse the repository at this point in the history
The code to run the demo tests starts a subprocess.
However, that python version may not have the required
libraries installed if FASTSim had been installed to
a virtual environment. This change makes it such that we
use the current python executable to also run the demo
tests. If that executable doesn't resolve (empty string or
None), then we default to just "python" and hope it is on
the path (and set up with FASTSim).
  • Loading branch information
Michael O'Keefe authored and Michael O'Keefe committed Oct 2, 2024
1 parent a6baa92 commit bb450fe
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/fastsim/demos/test_demos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import subprocess
import os
from pathlib import Path
Expand All @@ -22,8 +23,14 @@ def test_demo(demo_path: Path):
os.environ["SHOW_PLOTS"] = "false"
os.environ["TESTING"] = "true"

# NOTE: Try to set the python executable based on the current running python which
# MAY be running from a virtual environment.
python_exe = sys.executable
if python_exe == "" or python_exe is None:
python_exe = "python"

rslt = subprocess.run(
["python", demo_path],
[python_exe, demo_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
Expand Down

0 comments on commit bb450fe

Please sign in to comment.