#!/usr/bin/env python3 import subprocess import sys import os import venv def run_command(command, cwd=None, env=None): """Runs a shell command and raises error on failure.""" print(f"Running: {command}") try: subprocess.run(command, shell=True, check=True, cwd=cwd, env=env) except subprocess.CalledProcessError as e: print(f"Error running command: {command}") sys.exit(e.returncode) def main(): project_root = os.path.dirname(os.path.abspath(__file__)) venv_dir = os.path.join(project_root, "venv_tests") # 1. Create Virtual Environment if it doesn't exist if not os.path.exists(venv_dir): print("Creating virtual environment for tests...") venv.create(venv_dir, with_pip=True) # 2. Install dependencies print("Installing dependencies...") pip_executable = os.path.join(venv_dir, "bin", "pip") run_command(f"{pip_executable} install -r requirements.txt", cwd=project_root) # 3. Install Playwright browsers print("Installing Playwright browsers...") python_executable = os.path.join(venv_dir, "bin", "python") run_command(f"{python_executable} -m playwright install chromium", cwd=project_root) # 4. Run Pytest print("Running tests...") # Add venv/bin to PATH for the test run env = os.environ.copy() env["PATH"] = os.path.join(venv_dir, "bin") + os.pathsep + env["PATH"] test_command = f"{python_executable} -m pytest tests/test_e2e.py" # We execute this from the PARENT directory (project root) so paths in conftest work parent_dir = os.path.dirname(project_root) run_command(test_command, cwd=parent_dir, env=env) if __name__ == "__main__": main()