Skip to content

Commit

Permalink
test: workaround intermittent macos CI matplotlib failures (modflowpy…
Browse files Browse the repository at this point in the history
…#1491), don't use plt.show() in tests, add explanatory comments to conftest.py
  • Loading branch information
wpbonelli committed Aug 12, 2022
1 parent 76b3709 commit b73d11f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
16 changes: 13 additions & 3 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import importlib
import io
import os
import pkg_resources
import socket
import sys
from os import environ
Expand All @@ -14,6 +12,7 @@
from urllib import request
from warnings import warn

import pkg_resources
import pytest

# constants
Expand Down Expand Up @@ -139,7 +138,9 @@ def is_connected(hostname):


def is_in_ci():
return "CI" in os.environ
# if running in GitHub Actions CI, "CI" variable always set to true
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
return bool(os.environ.get("CI", None))


def is_github_rate_limited() -> Optional[bool]:
Expand Down Expand Up @@ -464,3 +465,12 @@ def run_py_script(script, *args, verbose=False):
"""Run a Python script, return tuple (stdout, stderr, returncode)."""
return run_cmd(
sys.executable, script, *args, verbose=verbose, cwd=Path(script).parent)


# use noninteractive matplotlib backend if in Mac OS CI to avoid pytest-xdist node failure
# e.g. https://github.com/modflowpy/flopy/runs/7748574375?check_suite_focus=true#step:9:57
@pytest.fixture(scope="session", autouse=True)
def patch_macos_ci_matplotlib():
if is_in_ci() and system().lower() == "darwin":
import matplotlib
matplotlib.use("agg")
13 changes: 11 additions & 2 deletions autotest/test_binarygrid_util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from platform import system

import matplotlib
import numpy as np
import pytest
from matplotlib import pyplot as plt

from flaky import flaky

from autotest.conftest import is_in_ci

# use noninteractive backend if in Mac OS CI to avoid occasional pytest-xdist node failure
# e.g. https://github.com/modflowpy/flopy/runs/7748574375?check_suite_focus=true#step:9:57
if is_in_ci() and system().lower() == "darwin":
matplotlib.use("agg")

from matplotlib import pyplot as plt

from flopy.discretization import StructuredGrid, UnstructuredGrid, VertexGrid
from flopy.mf6.utils import MfGrdFile

Expand Down
4 changes: 1 addition & 3 deletions autotest/test_sfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import matplotlib.pyplot as plt
import numpy as np
import pytest
from autotest.conftest import get_example_data_path, requires_exe, requires_pkg

from autotest.conftest import get_example_data_path, requires_exe, requires_pkg
from flopy.discretization import StructuredGrid
from flopy.modflow import Modflow, ModflowDis, ModflowSfr2, ModflowStr
from flopy.modflow.mfsfr2 import check
Expand Down Expand Up @@ -796,11 +796,9 @@ def test_sfr_plot(mf2005_model_path):
tv = sfr.plot(
key="strtop",
)
plt.show(block=False)
assert issubclass(
type(tv[0]), matplotlib.axes.SubplotBase
), "could not plot strtop"
plt.close("all")


def get_test_matrix():
Expand Down

0 comments on commit b73d11f

Please sign in to comment.