Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
TST: move test that requires interactive backend to subprocess
  • Loading branch information
tacaswell committed Jul 3, 2024
commit 1326835cdb5246a0fe7836226cf3751d383cb5a4
21 changes: 21 additions & 0 deletions lib/matplotlib/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,24 @@ def ipython_in_subprocess(requested_backend_or_gui_framework, all_expected_backe
)

assert proc.stdout.strip().endswith(f"'{expected_backend}'")


def is_ci_environment():
# Common CI variables
ci_environment_variables = [
'CI', # Generic CI environment variable
'CONTINUOUS_INTEGRATION', # Generic CI environment variable
'TRAVIS', # Travis CI
'CIRCLECI', # CircleCI
'JENKINS', # Jenkins
'GITLAB_CI', # GitLab CI
'GITHUB_ACTIONS', # GitHub Actions
'TEAMCITY_VERSION' # TeamCity
# Add other CI environment variables as needed
]

for env_var in ci_environment_variables:
if os.getenv(env_var):
return True

return False
23 changes: 1 addition & 22 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import matplotlib as mpl
from matplotlib import _c_internal_utils
from matplotlib.backend_tools import ToolToggleBase
from matplotlib.testing import subprocess_run_helper as _run_helper
from matplotlib.testing import subprocess_run_helper as _run_helper, is_ci_environment


class _WaitForStringPopen(subprocess.Popen):
Expand Down Expand Up @@ -110,27 +110,6 @@ def _get_testable_interactive_backends():
for env, marks in _get_available_interactive_backends()]


def is_ci_environment():
# Common CI variables
ci_environment_variables = [
'CI', # Generic CI environment variable
'CONTINUOUS_INTEGRATION', # Generic CI environment variable
'TRAVIS', # Travis CI
'CIRCLECI', # CircleCI
'JENKINS', # Jenkins
'GITLAB_CI', # GitLab CI
'GITHUB_ACTIONS', # GitHub Actions
'TEAMCITY_VERSION' # TeamCity
# Add other CI environment variables as needed
]

for env_var in ci_environment_variables:
if os.getenv(env_var):
return True

return False


# Reasonable safe values for slower CI/Remote and local architectures.
_test_timeout = 120 if is_ci_environment() else 20

Expand Down
13 changes: 10 additions & 3 deletions lib/matplotlib/tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import matplotlib as mpl
from matplotlib import cm
from matplotlib.testing import subprocess_run_helper
from matplotlib.testing import subprocess_run_helper, is_ci_environment
from matplotlib.testing.decorators import check_figures_equal
from matplotlib.dates import rrulewrapper
from matplotlib.lines import VertexSelector
Expand Down Expand Up @@ -311,7 +311,14 @@ def test_cycler():

# Run under an interactive backend to test that we don't try to pickle the
# (interactive and non-picklable) canvas.
@pytest.mark.backend('tkagg')
def test_axeswidget_interactive():
def _test_axeswidget_interactive():
ax = plt.figure().add_subplot()
pickle.dumps(mpl.widgets.Button(ax, "button"))


def test_axeswidget_interactive():
subprocess_run_helper(
_test_axeswidget_interactive,
timeout=120 if is_ci_environment() else 20,
extra_env={'MPLBACKEND': 'tkagg'}
)