Skip to content

Commit

Permalink
TST: Fix largescale pytest mark issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kohr-h committed Apr 13, 2020
1 parent 91fff6c commit adb1602
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 111 deletions.
4 changes: 2 additions & 2 deletions doc/source/dev/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ODL tests are run using pytest_, and there are several types:
Name Command Description
============== ========================= =======
Unit tests ``pytest`` Test "micro-features" of the code
Large-scale ``pytest --largescale`` Unit tests with large inputs and more cases
Large-scale ``pytest -S largescale`` Unit tests with large inputs and more cases
Doctests ``pytest`` Validate usage examples in docstrings
Examples ``pytest --examples`` Run all examples in the `examples`_ folder
Documentation ``pytest --doctest-doc`` Run the doctest examples in the Sphinx documentation
Expand All @@ -33,7 +33,7 @@ For more information consult the `pytest`_ documentation and look at existing te
def myfunction(x):
"""Convert ``x`` to a integer and add 1"""
"""Convert ``x`` to a integer and add 1."""
return int(x) + 1
Expand Down
8 changes: 2 additions & 6 deletions odl/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
[pytest]
minversion = 3.0.3
markers = not benchmark and not largescale
minversion = 5.4.0
testpaths = odl
doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ELLIPSIS
addopts = --doctest-modules
addopts = --doctest-modules --strict-markers
xfail_strict=true

# PEP8
pep8ignore =
E402
pep8maxlinelength = 79
# Temporary fix for https://github.com/odlgroup/odl/issues/1514, works with pytest<5.1
filterwarnings =
ignore::pytest.PytestDeprecationWarning
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2019 The ODL contributors
# Copyright 2014-2020 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -16,14 +16,13 @@

import odl
from odl.solvers.functional.functional import FunctionalDefaultConvexConjugate
from odl.util.testutils import (
all_almost_equal, noise_element, simple_fixture, skip_if_no_largescale)

from odl.util.testutils import all_almost_equal, noise_element, simple_fixture

# --- pytest fixtures --- #


pytestmark = skip_if_no_largescale
# Global pytest mark
pytestmark = pytest.mark.suite('largescale')


stepsize = simple_fixture('stepsize', [0.1, 1.0, 10.0])
Expand Down Expand Up @@ -72,8 +71,11 @@ def functional(request, linear_offset, quadratic_offset, dual):
outer_exp=outer_exp,
singular_vector_exp=singular_vector_exp)
elif name == 'quadratic':
func = odl.solvers.QuadraticForm(operator=odl.IdentityOperator(space),
vector=space.one(), constant=0.623)
func = odl.solvers.QuadraticForm(
operator=odl.IdentityOperator(space),
vector=space.one(),
constant=0.623,
)
elif name == 'linear':
func = odl.solvers.QuadraticForm(vector=space.one(), constant=0.623)
elif name == 'huber':
Expand All @@ -91,7 +93,8 @@ def functional(request, linear_offset, quadratic_offset, dual):

quadratic_coeff = 1.32
func = odl.solvers.FunctionalQuadraticPerturb(
func, quadratic_coeff=quadratic_coeff, linear_term=g)
func, quadratic_coeff=quadratic_coeff, linear_term=g
)

elif linear_offset:
g = noise_element(space)
Expand Down Expand Up @@ -279,4 +282,4 @@ def test_proximal_convex_conj_kl_cross_entropy_solving_opt_problem():


if __name__ == '__main__':
odl.util.test_file(__file__, ['--largescale'])
odl.util.test_file(__file__, ['-S', 'slow'])
11 changes: 5 additions & 6 deletions odl/test/largescale/space/tensor_space_slow_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2019 The ODL contributors
# Copyright 2014-2020 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -14,14 +14,13 @@
import pytest

import odl
from odl.util.testutils import (
all_almost_equal, dtype_tol, noise_elements, skip_if_no_largescale)

from odl.util.testutils import all_almost_equal, dtype_tol, noise_elements

# --- pytest fixtures --- #


pytestmark = skip_if_no_largescale
# Global pytest mark
pytestmark = pytest.mark.suite('largescale')


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


if __name__ == '__main__':
odl.util.test_file(__file__)
odl.util.test_file(__file__, ['-S', 'largescale'])
10 changes: 5 additions & 5 deletions odl/test/largescale/tomo/analytic_slow_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2020 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -17,13 +17,13 @@
import odl.tomo as tomo
from odl.tomo.util.testutils import (
skip_if_no_astra, skip_if_no_astra_cuda, skip_if_no_skimage)
from odl.util.testutils import simple_fixture, skip_if_no_largescale

from odl.util.testutils import simple_fixture

# --- pytest fixtures --- #


pytestmark = skip_if_no_largescale
# Global pytest mark
pytestmark = pytest.mark.suite('largescale')


filter_type = simple_fixture(
Expand Down Expand Up @@ -230,4 +230,4 @@ def test_fbp_reconstruction_filters(filter_type, frequency_scaling, weighting):


if __name__ == '__main__':
odl.util.test_file(__file__, ['--largescale'])
odl.util.test_file(__file__, ['-S', 'largescale'])
12 changes: 6 additions & 6 deletions odl/test/largescale/tomo/ray_transform_slow_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2019 The ODL contributors
# Copyright 2014-2020 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -17,13 +17,13 @@
import odl
from odl.tomo.util.testutils import (
skip_if_no_astra, skip_if_no_astra_cuda, skip_if_no_skimage)
from odl.util.testutils import simple_fixture, skip_if_no_largescale

from odl.util.testutils import all_almost_equal, simple_fixture

# --- pytest fixtures --- #


pytestmark = skip_if_no_largescale
# Global pytest mark
pytestmark = pytest.mark.suite('largescale')


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

# Verify A^*(y) == ((A^*)^*)^*(x)
assert proj_adj == proj_adj_adj_adj
assert all_almost_equal(proj_adj, proj_adj_adj_adj)


def test_reconstruction(projector):
Expand Down Expand Up @@ -243,4 +243,4 @@ def test_reconstruction(projector):


if __name__ == '__main__':
odl.util.test_file(__file__, ['--largescale'])
odl.util.test_file(__file__, ['-S', 'largescale'])
11 changes: 5 additions & 6 deletions odl/test/largescale/trafos/fourier_slow_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2019 The ODL contributors
# Copyright 2014-2020 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -18,14 +18,13 @@
import pytest

import odl
from odl.util.testutils import (
simple_fixture, skip_if_no_largescale, skip_if_no_pyfftw)

from odl.util.testutils import simple_fixture, skip_if_no_pyfftw

# --- pytest fixtures --- #


pytestmark = skip_if_no_largescale
# Global pytest mark
pytestmark = pytest.mark.suite('largescale')


impl = simple_fixture(
Expand Down Expand Up @@ -85,4 +84,4 @@ def charfun_freq_ball(x):


if __name__ == '__main__':
odl.util.test_file(__file__, ['--largescale'])
odl.util.test_file(__file__, ['-S', 'largescale'])
17 changes: 8 additions & 9 deletions odl/test/space/tensors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,21 @@ def _weighting_cls(impl, kind):
weight_ids = [' weight=1.0 ', ' weight=0.5 ', ' weight=<array> ']


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


@pytest.fixture(scope='module')
def tspace(odl_floating_dtype, odl_tspace_impl):
def tspace(odl_floating_dtype, odl_tspace_impl, weight):
impl = odl_tspace_impl
dtype = odl_floating_dtype
return odl.tensor_space(shape=(3, 4), dtype=dtype, impl=impl)
return odl.tensor_space(
shape=(3, 4), dtype=dtype, impl=impl, weighting=weight
)


# --- Space classes --- #
# --- Tests --- #


def test_init_npy_tspace():
Expand Down Expand Up @@ -451,8 +450,8 @@ def test_lincomb_discontig(odl_tspace_impl):
_test_lincomb(tspace, a, b, discontig=True)


def test_lincomb_raise(tspace):
"""Test if lincomb raises correctly for bad input."""
def test_lincomb_exceptions(tspace):
"""Test whether lincomb raises correctly for bad output element."""
other_space = odl.rn((4, 3), impl=tspace.impl)

other_x = other_space.zero()
Expand Down
10 changes: 3 additions & 7 deletions odl/test/util/normalize_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
length = simple_fixture('length', [1, 2])


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


@pytest.fixture(ids=single_conv_ids, params=single_conv_params)
@pytest.fixture(scope='module', ids=single_conv_ids, params=single_conv_params)
def single_conv(request):
return request.param

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


@pytest.fixture(ids=seq_conv_ids, params=seq_conv_params)
@pytest.fixture(scope='module', ids=seq_conv_ids, params=seq_conv_params)
def seq_conv(request):
return request.param

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


@pytest.fixture(ids=axes_conv_ids, params=axes_conv_params)
@pytest.fixture(scope='module', ids=axes_conv_ids, params=axes_conv_params)
def axes_conv(request):
return request.param

Expand Down
Loading

0 comments on commit adb1602

Please sign in to comment.