tests: test now runs each stimulus in browser and checks for errors #176
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test with py.test | |
on: | |
pull_request: | |
merge_group: | |
workflow_call: | |
push: | |
branches: | |
- main | |
jobs: | |
test: | |
strategy: | |
fail-fast: true | |
matrix: | |
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: "pip" | |
# 1) Install your package (and pytest) | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -e .[dev] | |
pip install pytest | |
shell: bash | |
# 2) Install Chromium on Linux | |
- name: Install Chromium (Linux) | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
# Try installing 'chromium-browser'; fallback to 'chromium' | |
sudo apt-get install -y chromium-browser || sudo apt-get install -y chromium | |
# 3) Install Chromium on macOS | |
- name: Install Chromium (macOS) | |
if: runner.os == 'macOS' | |
shell: bash | |
run: | | |
brew install chromium | |
# Set the path for Pyppeteer | |
echo "PYPPETEER_EXECUTABLE_PATH=$(which chromium)" >> $GITHUB_ENV | |
# 4) Install Chromium on Windows | |
- name: Install Chromium (Windows) | |
if: runner.os == 'Windows' | |
shell: powershell | |
run: | | |
choco install chromium -y | |
# Check the default install path: | |
$defaultChromeExe = "C:\Program Files\Chromium\Application\chrome.exe" | |
if (Test-Path $defaultChromeExe) { | |
# If it exists, use it | |
echo "PYPPETEER_EXECUTABLE_PATH=$defaultChromeExe" >> $env:GITHUB_ENV | |
} | |
else { | |
# Fallback: Try to detect "chrome" via Get-Command | |
$chromePath = (Get-Command chrome -ErrorAction SilentlyContinue).Source | |
if (!$chromePath) { | |
$chromePath = (Get-Command chrome.exe -ErrorAction SilentlyContinue).Source | |
} | |
if (!$chromePath) { | |
Write-Host "Chromium installation failed or not found!" | |
exit 1 | |
} | |
echo "PYPPETEER_EXECUTABLE_PATH=$chromePath" >> $env:GITHUB_ENV | |
} | |
# 5) Remove Pyppeteer’s auto-downloaded Chromium on macOS | |
- name: Remove Pyppeteer Chromium Cache (macOS) | |
if: runner.os == 'macOS' | |
run: rm -rf ~/Library/Application\ Support/pyppeteer/local-chromium | |
shell: bash | |
# 6) Symlink system Chromium (macOS, Linux) so Pyppeteer finds it | |
- name: Set up Pyppeteer (macOS/Linux) | |
if: runner.os != 'Windows' | |
shell: bash | |
run: | | |
mkdir -p ~/.local/share/pyppeteer/local-chromium | |
ln -sf $(which chromium-browser || which chromium || which chromium.app/Contents/MacOS/Chromium) \ | |
~/.local/share/pyppeteer/local-chromium/1181205 | |
# 7) Copy system Chromium (Windows) so Pyppeteer finds it | |
- name: Set up Pyppeteer (Windows) | |
if: runner.os == 'Windows' | |
shell: powershell | |
run: | | |
$chromePath = $env:PYPPETEER_EXECUTABLE_PATH | |
if (!$chromePath) { | |
Write-Host "Chromium path not found in GITHUB_ENV!" | |
exit 1 | |
} | |
if (!(Test-Path $chromePath)) { | |
Write-Host "Chromium file does not exist at $chromePath!" | |
exit 1 | |
} | |
New-Item -ItemType Directory -Force "$HOME\.local\share\pyppeteer\local-chromium" | Out-Null | |
Copy-Item $chromePath "$HOME\.local\share\pyppeteer\local-chromium\1181205" | |
# 8) Verify pytest is installed | |
- name: Check pytest installation | |
run: python -m pytest --version | |
# 9) Run tests | |
- name: Run tests | |
env: | |
PYPPETEER_EXECUTABLE_PATH: ${{ env.PYPPETEER_EXECUTABLE_PATH || '/usr/bin/chromium-browser' }} | |
run: python -m pytest tests/ |