Skip to content

Generate baseline hashes during tests to reduce flakiness #234

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 18 additions & 22 deletions .github/workflows/test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,27 @@ jobs:
- ghostscript
- inkscape
envs: |
# Test oldest NEP 29 configurations
# Test oldest SPEC 0 configurations
- linux: py311-test-mpl38
- macos: py311-test-mpl38
- windows: py311-test-mpl38
# Test newest configurations
- linux: py313-test-mpl310
- macos: py313-test-mpl310
- windows: py313-test-mpl310
# Test intermediate SPEC 0 configurations on Linux
- linux: py311-test-mpl39
- linux: py312-test-mpl39
- linux: py311-test-mpl310
- linux: py312-test-mpl310
# Test non-SPEC 0 configurations
- linux: py313-test-mpldev-pytestdev
- linux: py311-test-mpl37-pytest74
- linux: py39-test-mpl33-pytest62
# Test oldest non-SPEC 0 configurations
- linux: py39-test-mpl33
- macos: py39-test-mpl33
- windows: py39-test-mpl33
# Test oldest non-NEP 29 configurations
- linux: py36-test-mpl20
runs-on: ubuntu-20.04
- macos: py36-test-mpl20
- windows: py36-test-mpl20
# Test newest configurations
- linux: py312-test-mpl38
- macos: py312-test-mpl38
- windows: py312-test-mpl38
# Test intermediate NEP 29 configurations on Linux
- linux: py39-test-mpl38
- linux: py310-test-mpl38
- linux: py310-test-mpl35
- linux: py311-test-mpl36
- linux: py311-test-mpl37
# Test different versions of pytest
- linux: py312-test-mpldev-pytestdev
- linux: py39-test-mpl33-pytest62
- linux: py38-test-mpl31-pytest54
coverage: 'codecov'

publish:
Expand All @@ -57,7 +55,5 @@ jobs:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
with:
test_command: pytest $GITHUB_WORKSPACE/tests; pytest --mpl $GITHUB_WORKSPACE/tests
# Remove python-version when python-dateutil >2.8.2
python-version: "3.11"
secrets:
pypi_token: ${{ secrets.pypi_password }}
3 changes: 3 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ build:
tools:
python: "3.11"

sphinx:
configuration: docs/conf.py

python:
install:
- method: pip
Expand Down
2 changes: 1 addition & 1 deletion docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Installation Guide
##################

This plugin is compatible with Python 3.6 and later, and
This plugin is compatible with Python 3.9 and later, and
requires `pytest <http://pytest.org>`__ and
`matplotlib <http://www.matplotlib.org>`__ to be installed.

Expand Down
18 changes: 10 additions & 8 deletions pytest_mpl/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,22 +411,24 @@ def __init__(
self._test_stats = None
self.return_value = {}

def get_logger(self):
# configure a separate logger for this pluggin which is independent
# of the options that are configured for pytest or for the code that
# is tested; turn debug prints on only if "-vv" or more passed
level = logging.DEBUG if config.option.verbose > 1 else logging.INFO
if config.option.log_cli_format is not None:
fmt = config.option.log_cli_format
level = logging.DEBUG if self.config.option.verbose > 1 else logging.INFO
if self.config.option.log_cli_format is not None:
fmt = self.config.option.log_cli_format
else:
# use pytest's default fmt
fmt = "%(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)s"
formatter = logging.Formatter(fmt)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
self.logger = logging.getLogger('pytest-mpl')
self.logger.propagate = False
self.logger.setLevel(level)
self.logger.addHandler(handler)
logger = logging.getLogger('pytest-mpl')
logger.propagate = False
logger.setLevel(level)
logger.addHandler(handler)
return logger

def _file_extension(self, item):
compare = get_compare(item)
Expand Down Expand Up @@ -502,7 +504,7 @@ def _download_file(self, baseline, filename):
u = urlopen(base_url + filename)
content = u.read()
except Exception as e:
self.logger.info(f'Downloading {base_url + filename} failed: {repr(e)}')
self.get_logger().info(f'Downloading {base_url + filename} failed: {repr(e)}')
else:
break
else: # Could not download baseline image from any of the available URLs
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ long_description_content_type = text/x-rst
zip_safe = True
packages = find:
include_package_data = True
python_requires = >=3.6
python_requires = >=3.9
install_requires =
pytest
matplotlib
Expand All @@ -41,9 +41,9 @@ test =
pytest-cov
docs =
sphinx
mpl_sphinx_theme>=3.6.0.dev0
mpl_sphinx_theme>=3.9.0
sphinx_design
matplotlib==3.6
matplotlib==3.9.*

[tool:pytest]
testpaths = tests
Expand Down
7 changes: 0 additions & 7 deletions tests/baseline/hashes/mpl20_ft261.json

This file was deleted.

9 changes: 0 additions & 9 deletions tests/baseline/hashes/mpl21_ft261.json

This file was deleted.

9 changes: 0 additions & 9 deletions tests/baseline/hashes/mpl22_ft261.json

This file was deleted.

9 changes: 0 additions & 9 deletions tests/baseline/hashes/mpl30_ft261.json

This file was deleted.

9 changes: 0 additions & 9 deletions tests/baseline/hashes/mpl31_ft261.json

This file was deleted.

9 changes: 0 additions & 9 deletions tests/baseline/hashes/mpl32_ft261.json

This file was deleted.

10 changes: 0 additions & 10 deletions tests/baseline/hashes/mpl33_ft261.json

This file was deleted.

10 changes: 0 additions & 10 deletions tests/baseline/hashes/mpl34_ft261.json

This file was deleted.

10 changes: 0 additions & 10 deletions tests/baseline/hashes/mpl35_ft261.json

This file was deleted.

10 changes: 0 additions & 10 deletions tests/baseline/hashes/mpl36_ft261.json

This file was deleted.

10 changes: 0 additions & 10 deletions tests/baseline/hashes/mpl37_ft261.json

This file was deleted.

10 changes: 0 additions & 10 deletions tests/baseline/hashes/mpl38_ft261.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/baseline/test_hash_lib.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from pathlib import Path

import matplotlib
Expand All @@ -20,15 +19,11 @@ def skip_if_format_unsupported(file_format, using_hashes=False):
pytest.skip('SVG comparison is only supported in Matplotlib 3.3 and above')

if using_hashes:

if file_format == 'pdf' and MPL_VERSION < Version('2.1'):
pytest.skip('PDF hashes are only deterministic in Matplotlib 2.1 and above')
elif file_format == 'eps' and MPL_VERSION < Version('2.1'):
pytest.skip('EPS hashes are only deterministic in Matplotlib 2.1 and above')

if using_hashes and not sys.platform.startswith('linux'):
pytest.skip('Hashes for vector graphics are only provided in the hash library for Linux')

if file_format != 'png' and file_format not in converter:
if file_format == 'svg':
pytest.skip('Comparing SVG files requires inkscape to be installed')
Expand Down
34 changes: 0 additions & 34 deletions tests/subtests/result_hashes/mpl33_ft261.json

This file was deleted.

Loading
Loading