Skip to content
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ jobs:
with:
envs: |
- linux: codestyle
- windows: py39-test-pytestoldest
- linux: py39-test-pytest53
- macos: py39-test-pytest60
- windows: py39-test-pytest61
- windows: py39-test-pytest62
- linux: py310-test-pytest62
- macos: py310-test-pytest70
- windows: py310-test-pytest71
Expand All @@ -30,6 +27,9 @@ jobs:
- windows: py312-test-pytest74
- linux: py313-test-pytest83
- linux: py313-test-pytest90
- linux: py313-test-parallel
- linux: py314t-test
- linux: py314t-test-parallel
- linux: py313-test-devdeps
publish:
needs: tests
Expand Down
21 changes: 12 additions & 9 deletions pytest_arraydiff/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ def wrap_array_interceptor(plugin, item):
# Only intercept array on marked array tests
if item.get_closest_marker('array_compare') is not None:

# Guard against wrapping more than once (e.g. when pytest-run-parallel
# runs the same item multiple times).
if getattr(item.obj, '_arraydiff_wrapped', False):
return

# Use the full test name as a key to ensure correct array is being retrieved
test_name = generate_test_name(item)

def array_interceptor(store, obj):
def wrapper(*args, **kwargs):
store.return_value[test_name] = obj(*args, **kwargs)
wrapper._arraydiff_wrapped = True
return wrapper

item.obj = array_interceptor(plugin, item.obj)
Expand All @@ -260,6 +266,10 @@ def __init__(self, config, reference_dir=None, generate_dir=None, default_format
self.default_format = default_format
self.return_value = {}

def pytest_collection_modifyitems(self, items):
for item in items:
wrap_array_interceptor(self, item)

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item):

Expand Down Expand Up @@ -298,8 +308,6 @@ def pytest_runtest_call(self, item):

baseline_remote = reference_dir.startswith('http')

# Run test and get array object
wrap_array_interceptor(self, item)
yield
test_name = generate_test_name(item)
if test_name not in self.return_value:
Expand Down Expand Up @@ -372,11 +380,6 @@ def __init__(self, config):
self.config = config
self.return_value = {}

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item):

if item.get_closest_marker('array_compare') is not None:
def pytest_collection_modifyitems(self, items):
for item in items:
wrap_array_interceptor(self, item)

yield
return
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ python_requires = >=3.9
setup_requires =
setuptools_scm
install_requires =
pytest>=5.0
pytest>=6.2
numpy

# tables limitation is until 3.9.3 is out as that supports ARM OSX.
[options.extras_require]
test =
astropy
pandas
test_hdf5 =
tables;platform_machine!='arm64'

[options.entry_points]
pytest11 =
pytest_arraydiff = pytest_arraydiff.plugin

[tool:pytest]
minversion = 5.0
minversion = 6.2
testpaths = tests
xfail_strict = true
markers =
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest_plugins = ["pytester"]
29 changes: 29 additions & 0 deletions tests/test_pytest_arraydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,32 @@ def test_single_reference(self, spam):

def test_nofile():
pass


TEST_PARALLEL = """
import pytest
import numpy as np
from astropy.io import fits
@pytest.mark.array_compare(file_format='fits')
def test_parallel():
return fits.PrimaryHDU(np.arange(3 * 5).reshape((3, 5)).astype(np.int64))
"""


def test_parallel_iterations(pytester):
"""Regression test: arraydiff should work with pytest-run-parallel."""
pytest.importorskip('pytest_run_parallel')

pytester.makepyfile(test_parallel=TEST_PARALLEL)
gen_dir = pytester.path / 'reference'

# Generate the reference file first
result = pytester.runpytest_subprocess(f'--arraydiff-generate-path={gen_dir}')
assert result.ret == 0

# Now run with --arraydiff and multiple iterations
result = pytester.runpytest_subprocess(
'--arraydiff', f'--arraydiff-reference-path={gen_dir}',
'--parallel-threads=2', '--iterations=3',
)
assert result.ret == 0
14 changes: 8 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
[tox]
envlist =
py{39,310,311,312,313,314}-test{,-pytestoldest,-pytest52,-pytest53,-pytest60,-pytest61,-pytest62,-pytest70,-pytest71,-pytest72,-pytest73,-pytest74,-devdeps}
py{39,310,311,312,313,314}-test{,-pytest62,-pytest70,-pytest71,-pytest72,-pytest73,-pytest74,-devdeps}
py{313t,314t}-test{,-parallel}
codestyle
isolated_build = true

[testenv]
changedir = .tmp/{envname}
setenv =
py313t,py314t: PYTHON_GIL = 0
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/liberfa/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
description = run tests
deps =
pytestoldest: pytest==5.0.0
pytest52: pytest==5.2.*
pytest53: pytest==5.3.*
pytest60: pytest==6.0.*
pytest61: pytest==6.1.*
pytest62: pytest==6.2.*
pytest70: pytest==7.0.*
pytest71: pytest==7.1.*
Expand All @@ -24,13 +21,18 @@ deps =
pytest80: pytest==8.0.*
pytest83: pytest==8.3.*
pytest90: pytest==9.0.*
parallel: pytest-run-parallel
devdeps: git+https://github.com/pytest-dev/pytest#egg=pytest
devdeps: numpy>=0.0.dev0
devdeps: pandas>=0.0.dev0
devdeps: pyerfa>=0.0.dev0
devdeps: astropy>=0.0.dev0
extras =
test
# tables (PyTables) is needed for the pandas/HDF5 file_format, but
# has no free-threaded wheels and its sdist requires libhdf5-dev,
# which CI does not install. Only run these test on GIL-enabled builds.
!py313t-!py314t: test_hdf5
commands =
# Force numpy-dev after something in the stack downgrades it
devdeps: python -m pip install --pre --upgrade --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
Expand Down
Loading