Skip to content

Add tests for WebAgg using Playwright #23540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ install:
- activate mpl-dev
- conda install -c conda-forge pywin32
- echo %PYTHON_VERSION% %TARGET_ARCH%
# Install browsers for testing
- playwright install --with-deps
# Show the installed packages + versions
- conda list

Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ jobs:
~/.cache/matplotlib
!~/.cache/matplotlib/tex.cache
!~/.cache/matplotlib/test_cache
key: 4-${{ runner.os }}-py${{ matrix.python-version }}-mpl-${{ github.ref }}-${{ github.sha }}
key: 5-${{ runner.os }}-py${{ matrix.python-version }}-mpl-${{ github.ref }}-${{ github.sha }}
restore-keys: |
4-${{ runner.os }}-py${{ matrix.python-version }}-mpl-${{ github.ref }}-
4-${{ runner.os }}-py${{ matrix.python-version }}-mpl-
5-${{ runner.os }}-py${{ matrix.python-version }}-mpl-${{ github.ref }}-
5-${{ runner.os }}-py${{ matrix.python-version }}-mpl-

- name: Install Python dependencies
run: |
Expand Down Expand Up @@ -281,6 +281,9 @@ jobs:
--index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
--upgrade --only-binary=:all: numpy pandas

- name: Install browsers for testing
run: playwright install --with-deps

- name: Install Matplotlib
run: |
ccache -s
Expand Down Expand Up @@ -311,6 +314,8 @@ jobs:
- name: Run pytest
run: |
pytest -rfEsXR -n auto \
--browser chromium --browser firefox --browser webkit \
--slowmo=100 --tracing=on --video=on \
--maxfail=50 --timeout=300 --durations=25 \
--cov-report=xml --cov=lib --log-level=DEBUG --color=yes

Expand Down Expand Up @@ -377,6 +382,12 @@ jobs:
name: "${{ matrix.python-version }} ${{ matrix.os }} ${{ matrix.name-suffix }} result images"
path: ./result_images

- uses: actions/upload-artifact@v3
if: failure()
with:
name: "${{ matrix.python-version }} ${{ matrix.os }} ${{ matrix.name-suffix }} playwright"
path: ./test-results

# Separate dependent job to only upload one issue from the matrix of jobs
create-issue:
if: ${{ failure() && github.event_name == 'schedule' }}
Expand Down
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ stages:
--verbose --editable .[dev]
displayName: "Install self"

- bash: playwright install --with-deps
displayName: 'Install browsers for testing'

- script: env
displayName: 'print env'

Expand Down Expand Up @@ -225,6 +228,7 @@ stages:
fi
PYTHONFAULTHANDLER=1 pytest -rfEsXR -n 2 \
--maxfail=50 --timeout=300 --durations=25 \
--browser chromium --browser firefox --browser webkit \
--junitxml=junit/test-results.xml --cov-report=xml --cov=lib
if [[ -n $SESSION_ID ]]; then
if [[ $VS_VER == 2022 ]]; then
Expand Down
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ dependencies:
- nbconvert[execute]!=6.0.0,!=6.0.1,!=7.3.0,!=7.3.1
- nbformat!=5.0.0,!=5.0.1
- pandas!=0.25.0
- pip:
- pytest-playwright
- psutil
- pre-commit
- pydocstyle>=5.1.0
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_webagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ def random_ports(port, n):
cls.address = mpl.rcParams['webagg.address']
else:
cls.address = address
cls.port = mpl.rcParams['webagg.port']
for port in random_ports(cls.port,
mpl.rcParams['webagg.port_retries']):
if port is None:
port = mpl.rcParams['webagg.port']
for port in random_ports(port, mpl.rcParams['webagg.port_retries']):
try:
app.listen(port, cls.address)
except OSError as e:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions lib/matplotlib/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
import contextlib
import socket

import pytest

from matplotlib.testing.conftest import ( # noqa
mpl_test_settings, pytest_configure, pytest_unconfigure, pd, xr)


@pytest.fixture
def random_port():
with contextlib.closing(
socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 0))
s.listen(1)
addr = s.getsockname()
port = addr[1]

return port
Loading
Loading