Skip to content

Commit 0630955

Browse files
committed
TST: Fix largescale pytest mark issue
We change the command-line option to a version recommended in the pytest docs: https://docs.pytest.org/en/latest/example/markers.html#custom-marker-and-command-line-option-to-control-test-runs - A global `suite(name)` mark is registered, that takes a name and marks a test as belonging to a specific suite. - These special suites are opt-in, i.e., not run by default. - To enable a suite, one adds `-S name` to the pytest command-line options. - Since function-scoped fixtures are handled stricter now, the workaround in tensors_test.py didn't work any longer (see pytest-dev/pytest#6497). - We thus set the minimum pytest version to 5.4.0, where the fix for the issue is implemented. Closes: odlgroup#1514
1 parent 91fff6c commit 0630955

File tree

12 files changed

+108
-109
lines changed

12 files changed

+108
-109
lines changed

doc/source/dev/testing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ODL tests are run using pytest_, and there are several types:
1111
Name Command Description
1212
============== ========================= =======
1313
Unit tests ``pytest`` Test "micro-features" of the code
14-
Large-scale ``pytest --largescale`` Unit tests with large inputs and more cases
14+
Large-scale ``pytest -S largescale`` Unit tests with large inputs and more cases
1515
Doctests ``pytest`` Validate usage examples in docstrings
1616
Examples ``pytest --examples`` Run all examples in the `examples`_ folder
1717
Documentation ``pytest --doctest-doc`` Run the doctest examples in the Sphinx documentation
@@ -33,7 +33,7 @@ For more information consult the `pytest`_ documentation and look at existing te
3333
3434
3535
def myfunction(x):
36-
"""Convert ``x`` to a integer and add 1"""
36+
"""Convert ``x`` to a integer and add 1."""
3737
return int(x) + 1
3838
3939

odl/pytest.ini

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
[pytest]
2-
minversion = 3.0.3
3-
markers = not benchmark and not largescale
2+
minversion = 5.4.0
43
testpaths = odl
54
doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ELLIPSIS
6-
addopts = --doctest-modules
5+
addopts = --doctest-modules --strict-markers
76
xfail_strict=true
87

98
# PEP8
109
pep8ignore =
1110
E402
1211
pep8maxlinelength = 79
13-
# Temporary fix for https://github.com/odlgroup/odl/issues/1514, works with pytest<5.1
14-
filterwarnings =
15-
ignore::pytest.PytestDeprecationWarning

odl/test/largescale/solvers/nonsmooth/default_functionals_slow_test.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014-2019 The ODL contributors
1+
# Copyright 2014-2020 The ODL contributors
22
#
33
# This file is part of ODL.
44
#
@@ -16,14 +16,13 @@
1616

1717
import odl
1818
from odl.solvers.functional.functional import FunctionalDefaultConvexConjugate
19-
from odl.util.testutils import (
20-
all_almost_equal, noise_element, simple_fixture, skip_if_no_largescale)
21-
19+
from odl.util.testutils import all_almost_equal, noise_element, simple_fixture
2220

2321
# --- pytest fixtures --- #
2422

2523

26-
pytestmark = skip_if_no_largescale
24+
# Global pytest mark
25+
pytestmark = pytest.mark.suite('largescale')
2726

2827

2928
stepsize = simple_fixture('stepsize', [0.1, 1.0, 10.0])
@@ -72,8 +71,11 @@ def functional(request, linear_offset, quadratic_offset, dual):
7271
outer_exp=outer_exp,
7372
singular_vector_exp=singular_vector_exp)
7473
elif name == 'quadratic':
75-
func = odl.solvers.QuadraticForm(operator=odl.IdentityOperator(space),
76-
vector=space.one(), constant=0.623)
74+
func = odl.solvers.QuadraticForm(
75+
operator=odl.IdentityOperator(space),
76+
vector=space.one(),
77+
constant=0.623,
78+
)
7779
elif name == 'linear':
7880
func = odl.solvers.QuadraticForm(vector=space.one(), constant=0.623)
7981
elif name == 'huber':
@@ -91,7 +93,8 @@ def functional(request, linear_offset, quadratic_offset, dual):
9193

9294
quadratic_coeff = 1.32
9395
func = odl.solvers.FunctionalQuadraticPerturb(
94-
func, quadratic_coeff=quadratic_coeff, linear_term=g)
96+
func, quadratic_coeff=quadratic_coeff, linear_term=g
97+
)
9598

9699
elif linear_offset:
97100
g = noise_element(space)
@@ -279,4 +282,4 @@ def test_proximal_convex_conj_kl_cross_entropy_solving_opt_problem():
279282

280283

281284
if __name__ == '__main__':
282-
odl.util.test_file(__file__, ['--largescale'])
285+
odl.util.test_file(__file__, ['-S', 'slow'])

odl/test/largescale/space/tensor_space_slow_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014-2019 The ODL contributors
1+
# Copyright 2014-2020 The ODL contributors
22
#
33
# This file is part of ODL.
44
#
@@ -14,14 +14,13 @@
1414
import pytest
1515

1616
import odl
17-
from odl.util.testutils import (
18-
all_almost_equal, dtype_tol, noise_elements, skip_if_no_largescale)
19-
17+
from odl.util.testutils import all_almost_equal, dtype_tol, noise_elements
2018

2119
# --- pytest fixtures --- #
2220

2321

24-
pytestmark = skip_if_no_largescale
22+
# Global pytest mark
23+
pytestmark = pytest.mark.suite('largescale')
2524

2625

2726
spc_params = ['rn', '1d', '3d']
@@ -333,4 +332,4 @@ def idiv_aliased(x):
333332

334333

335334
if __name__ == '__main__':
336-
odl.util.test_file(__file__)
335+
odl.util.test_file(__file__, ['-S', 'largescale'])

odl/test/largescale/tomo/analytic_slow_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014-2017 The ODL contributors
1+
# Copyright 2014-2020 The ODL contributors
22
#
33
# This file is part of ODL.
44
#
@@ -17,13 +17,13 @@
1717
import odl.tomo as tomo
1818
from odl.tomo.util.testutils import (
1919
skip_if_no_astra, skip_if_no_astra_cuda, skip_if_no_skimage)
20-
from odl.util.testutils import simple_fixture, skip_if_no_largescale
21-
20+
from odl.util.testutils import simple_fixture
2221

2322
# --- pytest fixtures --- #
2423

2524

26-
pytestmark = skip_if_no_largescale
25+
# Global pytest mark
26+
pytestmark = pytest.mark.suite('largescale')
2727

2828

2929
filter_type = simple_fixture(
@@ -230,4 +230,4 @@ def test_fbp_reconstruction_filters(filter_type, frequency_scaling, weighting):
230230

231231

232232
if __name__ == '__main__':
233-
odl.util.test_file(__file__, ['--largescale'])
233+
odl.util.test_file(__file__, ['-S', 'largescale'])

odl/test/largescale/tomo/ray_transform_slow_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014-2019 The ODL contributors
1+
# Copyright 2014-2020 The ODL contributors
22
#
33
# This file is part of ODL.
44
#
@@ -17,13 +17,13 @@
1717
import odl
1818
from odl.tomo.util.testutils import (
1919
skip_if_no_astra, skip_if_no_astra_cuda, skip_if_no_skimage)
20-
from odl.util.testutils import simple_fixture, skip_if_no_largescale
21-
20+
from odl.util.testutils import all_almost_equal, simple_fixture
2221

2322
# --- pytest fixtures --- #
2423

2524

26-
pytestmark = skip_if_no_largescale
25+
# Global pytest mark
26+
pytestmark = pytest.mark.suite('largescale')
2727

2828

2929
dtype_params = ['float32', 'float64', 'complex64']
@@ -212,7 +212,7 @@ def test_adjoint_of_adjoint(projector):
212212
proj_adj_adj_adj = projector.adjoint.adjoint.adjoint(proj)
213213

214214
# Verify A^*(y) == ((A^*)^*)^*(x)
215-
assert proj_adj == proj_adj_adj_adj
215+
assert all_almost_equal(proj_adj, proj_adj_adj_adj)
216216

217217

218218
def test_reconstruction(projector):
@@ -243,4 +243,4 @@ def test_reconstruction(projector):
243243

244244

245245
if __name__ == '__main__':
246-
odl.util.test_file(__file__, ['--largescale'])
246+
odl.util.test_file(__file__, ['-S', 'largescale'])

odl/test/largescale/trafos/fourier_slow_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014-2019 The ODL contributors
1+
# Copyright 2014-2020 The ODL contributors
22
#
33
# This file is part of ODL.
44
#
@@ -18,14 +18,13 @@
1818
import pytest
1919

2020
import odl
21-
from odl.util.testutils import (
22-
simple_fixture, skip_if_no_largescale, skip_if_no_pyfftw)
23-
21+
from odl.util.testutils import simple_fixture, skip_if_no_pyfftw
2422

2523
# --- pytest fixtures --- #
2624

2725

28-
pytestmark = skip_if_no_largescale
26+
# Global pytest mark
27+
pytestmark = pytest.mark.suite('largescale')
2928

3029

3130
impl = simple_fixture(
@@ -85,4 +84,4 @@ def charfun_freq_ball(x):
8584

8685

8786
if __name__ == '__main__':
88-
odl.util.test_file(__file__, ['--largescale'])
87+
odl.util.test_file(__file__, ['-S', 'largescale'])

odl/test/space/tensors_test.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ def _weighting_cls(impl, kind):
9393
weight_ids = [' weight=1.0 ', ' weight=0.5 ', ' weight=<array> ']
9494

9595

96-
# scope='module' removed due to pytest issue, see
97-
# https://github.com/pytest-dev/pytest/issues/6497
98-
# TODO: re-introduce when fixed
99-
@pytest.fixture(params=weight_params, ids=weight_ids)
96+
@pytest.fixture(scope='module', params=weight_params, ids=weight_ids)
10097
def weight(request):
10198
return request.param
10299

@@ -108,7 +105,7 @@ def tspace(odl_floating_dtype, odl_tspace_impl):
108105
return odl.tensor_space(shape=(3, 4), dtype=dtype, impl=impl)
109106

110107

111-
# --- Space classes --- #
108+
# --- Tests --- #
112109

113110

114111
def test_init_npy_tspace():
@@ -451,8 +448,8 @@ def test_lincomb_discontig(odl_tspace_impl):
451448
_test_lincomb(tspace, a, b, discontig=True)
452449

453450

454-
def test_lincomb_raise(tspace):
455-
"""Test if lincomb raises correctly for bad input."""
451+
def test_lincomb_exceptions(tspace):
452+
"""Test whether lincomb raises correctly for bad output element."""
456453
other_space = odl.rn((4, 3), impl=tspace.impl)
457454

458455
other_x = other_space.zero()

odl/test/util/normalize_test.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
length = simple_fixture('length', [1, 2])
2323

2424

25-
# For this and other fixtures below:
26-
# scope='module' removed due to pytest issue, see
27-
# https://github.com/pytest-dev/pytest/issues/6497
28-
# TODO: re-introduce when fixed
2925
single_conv_params = [(-1.0, float),
3026
(2, float),
3127
('10', float),
@@ -41,7 +37,7 @@
4137
for p in single_conv_params]
4238

4339

44-
@pytest.fixture(ids=single_conv_ids, params=single_conv_params)
40+
@pytest.fixture(scope='module', ids=single_conv_ids, params=single_conv_params)
4541
def single_conv(request):
4642
return request.param
4743

@@ -64,7 +60,7 @@ def single_conv(request):
6460
for p in seq_conv_params]
6561

6662

67-
@pytest.fixture(ids=seq_conv_ids, params=seq_conv_params)
63+
@pytest.fixture(scope='module', ids=seq_conv_ids, params=seq_conv_params)
6864
def seq_conv(request):
6965
return request.param
7066

@@ -82,7 +78,7 @@ def seq_conv(request):
8278
for axis in axes_conv_params]
8379

8480

85-
@pytest.fixture(ids=axes_conv_ids, params=axes_conv_params)
81+
@pytest.fixture(scope='module', ids=axes_conv_ids, params=axes_conv_params)
8682
def axes_conv(request):
8783
return request.param
8884

0 commit comments

Comments
 (0)