Skip to content

[Bug]: test_invisible_Line_rendering test is flaky (too short timeout) #30809

@apteryks

Description

@apteryks

Bug summary

Hi,

Running the test suite of 3.10.8 a couple times, eventually I got:

=================================== FAILURES ===================================
________________________ test_invisible_Line_rendering _________________________
[gw11] linux -- Python 3.11.11 /gnu/store/v76lvm9985mj5h3kwrkif7gnqv3q30ck-python-wrapper-3.11.11/bin/python

    @pytest.mark.flaky(reruns=3)
    def test_invisible_Line_rendering():
        """
        GitHub issue #1256 identified a bug in Line.draw method
    
        Despite visibility attribute set to False, the draw method was not
        returning early enough and some pre-rendering code was executed
        though not necessary.
    
        Consequence was an excessive draw time for invisible Line instances
        holding a large number of points (Npts> 10**6)
        """
        # Creates big x and y data:
        N = 10**7
        x = np.linspace(0, 1, N)
        y = np.random.normal(size=N)
    
        # Create a plot figure:
        fig = plt.figure()
        ax = plt.subplot()
    
        # Create a "big" Line instance:
        l = mlines.Line2D(x, y)
        l.set_visible(False)
        # but don't add it to the Axis instance `ax`
    
        # [here Interactive panning and zooming is pretty responsive]
        # Time the canvas drawing:
        t_no_line = min(timeit.repeat(fig.canvas.draw, number=1, repeat=3))
        # (gives about 25 ms)
    
        # Add the big invisible Line:
        ax.add_line(l)
    
        # [Now interactive panning and zooming is very slow]
        # Time the canvas drawing:
        t_invisible_line = min(timeit.repeat(fig.canvas.draw, number=1, repeat=3))
        # gives about 290 ms for N = 10**7 pts
    
        slowdown_factor = t_invisible_line / t_no_line
        slowdown_threshold = 2  # trying to avoid false positive failures
>       assert slowdown_factor < slowdown_threshold
E       assert 2.218287122977422 < 2

/gnu/store/j1595nb44lp30vbjd9c8iadzf8z7d3ry-python-matplotlib-3.10.8/lib/python3.11/site-packages/matplotlib/tests/test_lines.py:77: AssertionError
------------------------------ Captured log setup ------------------------------
WARNING  matplotlib.testing:__init__.py:38 Could not set locale to English/United States. Some date-related tests may fail.
=========================== short test summary info ============================
FAILED tests/test_lines.py::test_invisible_Line_rendering - assert 2.218287122977422 < 2
========== 1 failed, 6592 passed, 1521 skipped, 29 xfailed in 24.07s ===========

Code for reproduction

I build on Guix with this package:

(define-public python-matplotlib
  (package
    (name "python-matplotlib")
    (version "3.10.8")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                     (url "https://github.com/matplotlib/matplotlib")
                     (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "1rlday52hcyrp7xfbdf4z8lzgnxkpfvjxnl9qmq0jvc3ph3n8k5i"))))
    (build-system pyproject-build-system)
    (arguments
     (list
      #:configure-flags
      ''(("setup-args" . #("-DrcParams-backend=TkAgg"
                           "-Dsystem-freetype=true"
                           "-Dsystem-qhull=true"))
         ("install-args" . "--tags=data,python-runtime,runtime,tests"))
      #:test-flags
      #~(list "-m" "not network"
              "-n" (number->string (parallel-job-count))
              ;; Run the installed tests, which is what we want since not
              ;; everything gets built in the source directory.
              "--pyargs" "matplotlib"
              "-k"
              (string-join
               (list
                ;; XXX: Disable all image comparison tests because we're using
                ;; a newer version of FreeType than matplotlib expects.  This
                ;; leads to minor differences throughout the tests.
                "not image_comparison"
                "check_figures_equal"
                "png"                   ;disables many problematic image tests
                "test_figure_legend_outside"
                "test_ft2font_get_kerning"
                "test_normal_axes"
                "test_get_tightbbox_polar")
               " and not "))
      #:phases
      #~(modify-phases %standard-phases
          (add-before 'build 'pretend-version
            ;; The version string is usually derived via setuptools-scm, but
            ;; without the git metadata available, the version string is set to
            ;; '0.0.0'.
            (lambda _
              (setenv "SETUPTOOLS_SCM_PRETEND_VERSION" #$version)))
          (add-after 'unpack 'patch-commands
            (lambda _
              (substitute* "lib/matplotlib/tests/test_animation.py"
                (("/bin/sh") (which "sh")))))
          (add-after 'unpack 'patch-dlopen
            (lambda* (#:key inputs #:allow-other-keys)
              (substitute* "src/_c_internal_utils.cpp"
                (("libX11.so.6")
                 (search-input-file inputs "lib/libX11.so.6")))))
          (add-before 'build 'configure-environment
            (lambda* (#:key inputs #:allow-other-keys)
              ;; Fix rounding errors when using the x87 FPU.
              (when (string-prefix? "i686" #$(%current-system))
                (setenv "CFLAGS" "-ffloat-store"))))
          (add-before 'check 'chdir
            (lambda _
              ;; Step out of the source directory to avoid interference.
              (chdir "/tmp"))))))
    (propagated-inputs
     (list python-contourpy
           python-cycler
           python-dateutil
           python-fonttools-minimal
           python-importlib-resources
           python-kiwisolver
           python-numpy
           python-packaging
           python-pillow
           python-pyparsing
           `(,python "tk")))
    (inputs
     (list cairo
           freetype
           glib
           libpng
           qhull
           tcl
           tk))
    (native-inputs
     (list meson-python
           pkg-config
           pybind11
           python-pytest
           python-pytest-timeout
           python-pytest-xdist
           python-setuptools
           python-setuptools-scm
           python-wheel))
    (home-page "https://matplotlib.org/")
    (synopsis "2D plotting library for Python")
    (description
     "Matplotlib is a Python 2D plotting library which produces publication
quality figures in a variety of hardcopy formats and interactive environments
across platforms.  Matplotlib can be used in Python scripts, the python and
ipython shell, web application servers, and six graphical user interface
toolkits.")
    (license license:psfl)))

But it should be reproducible anywhere.

Actual outcome

Test fails.

Expected outcome

Test should pass.

Additional information

No response

Operating system

Guix System

Matplotlib Version

3.10.8

Matplotlib Backend

No response

Python version

3.11.11

Jupyter version

No response

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions