Repository: jupyter/nbconvert
Pull request #1924 (2022-12-18 02:15:33)

Fix Hanging Tests on Linux
The tests are hanging on downstream tests, e.g. https://github.com/ipython/traitlets/actions/runs/3722005188/jobs/6312540850.

Reason: Both PyQtWebEngine and Pyppeteer are hanging on Ubuntu 22.04, which is now the default runner.  

Pyppeteer is deprecated, but I was unsuccessful in #1919 in trying to replace it with Playwright, due to having problems installing properly in CI.

Either way, we no longer require webpdf for the base testing, so we're not relying on external binaries.


Patch:
diff --git a/nbconvert/exporters/webpdf.py b/nbconvert/exporters/webpdf.py
index a9564857..10f6bac5 100644
--- a/nbconvert/exporters/webpdf.py
+++ b/nbconvert/exporters/webpdf.py
@@ -12,6 +12,13 @@ from traitlets import Bool, default
 
 from .html import HTMLExporter
 
+try:
+    import pyppeteer  # noqa
+
+    PYPPETEER_INSTALLED = True
+except ImportError:
+    PYPPETEER_INSTALLED = False
+
 
 class WebPDFExporter(HTMLExporter):
     """Writer designed to write to PDF files.
diff --git a/pyproject.toml b/pyproject.toml
index 0066467a..764b7647 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -65,7 +65,6 @@ test = [
     "ipykernel",
     "ipywidgets>=7",
     "pre-commit",
-    "pyppeteer>=1,<1.1",
 ]
 serve = ["tornado>=6.1"]
 docs = [


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 263b8962..5a333a70 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -20,12 +20,12 @@ jobs:
       NBFORMAT_VALIDATOR: jsonschema
     strategy:
       matrix:
-        os: ["ubuntu-latest", "macos-latest", "windows-latest"]
+        os: ["ubuntu-20.04", "macos-latest", "windows-latest"]
         python-version: ["3.7", "3.10"]
         include:
           - os: "windows-latest"
             python-version: "3.8"
-          - os: "ubuntu-latest"
+          - os: "ubuntu-20.04"
             python-version: "3.9"
       fail-fast: false
     steps:
diff --git a/nbconvert/exporters/tests/test_webpdf.py b/nbconvert/exporters/tests/test_webpdf.py
index 994324fd..06916e95 100644
--- a/nbconvert/exporters/tests/test_webpdf.py
+++ b/nbconvert/exporters/tests/test_webpdf.py
@@ -7,10 +7,11 @@ from unittest.mock import patch
 
 import pytest
 
-from ..webpdf import WebPDFExporter
+from ..webpdf import PYPPETEER_INSTALLED, WebPDFExporter
 from .base import ExportersTestsBase
 
 
+@pytest.mark.skipif(not PYPPETEER_INSTALLED, reason="Pyppeteer not installed")
 class TestWebPDFExporter(ExportersTestsBase):
     """Contains test functions for webpdf.py"""
 
diff --git a/nbconvert/tests/test_nbconvertapp.py b/nbconvert/tests/test_nbconvertapp.py
index 45b0cddb..b6ed3c0e 100644
--- a/nbconvert/tests/test_nbconvertapp.py
+++ b/nbconvert/tests/test_nbconvertapp.py
@@ -11,6 +11,7 @@ import pytest
 from traitlets.tests.utils import check_help_all_output
 
 from nbconvert.exporters import HTMLExporter
+from nbconvert.exporters.webpdf import PYPPETEER_INSTALLED
 
 from ..postprocessors import PostProcessorBase
 from ..tests.utils import onlyif_cmds_exist
@@ -148,6 +149,7 @@ class TestNbConvertApp(TestsBase):
             assert os.path.isfile("notebook with spaces.pdf")
 
     @pytest.mark.network
+    @pytest.mark.skipif(not PYPPETEER_INSTALLED, reason="Pyppeeter not installed")
     def test_webpdf_with_chromium(self):
         """
         Generate PDFs if chromium allowed to be downloaded?