Skip to content
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

TST: Fix largescale pytest mark issue #1553

Merged
merged 8 commits into from
Apr 15, 2020
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
22 changes: 11 additions & 11 deletions doc/source/dev/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Testing in ODL
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
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
============== ========================= =======
============== ========================== =======
Name Command Description
============== ========================== =======
Unit tests ``pytest`` Test "micro-features" of the code
Large-scale ``pytest -S largescale`` Unit tests with large inputs and more cases
Doctests ``pytest`` Validate usage examples in docstrings
Examples ``pytest -S examples`` Run all examples in the `examples`_ folder
Documentation ``pytest -S doc_doctests`` Run the doctest examples in the Sphinx documentation
============== ========================== =======

Unit tests
~~~~~~~~~~
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 Expand Up @@ -116,7 +116,7 @@ Examples
Examples, while not technically tests in the traditional sense, still constitute a part of the test framework for ODL by showing how different parts of ODL work together and by ensuring that functions that depend on each other work as expected.
The main purpose of the examples is however to show ODL from a users perspective and particular care should be taken to keep them readable and working since this is often the first thing users see when they start using ODL.

It is even possible to run all examples as part of the test suite by running ``pytest --examples``, but be aware that this requires all ODL dependencies to be installed and that plotting windows can be opened during execution.
It is even possible to run all examples as part of the test suite by running ``pytest -S examples``, but be aware that this requires all ODL dependencies to be installed and can take a long time.

Consult the `examples`_ directory for an impression of the style in which ODL examples are written.

Expand Down
7 changes: 1 addition & 6 deletions odl/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
[pytest]
minversion = 3.0.3
markers = not benchmark and not largescale
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', 'largescale'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't '-S largescale' be more appropriate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's indeed how you give it on the command line. Here it's just a list of arguments to the call, and from what I've seen it's more common to give it in "already pre-parsed" form, i.e., each argument as a separate element of the list.

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'])
11 changes: 4 additions & 7 deletions odl/test/space/tensors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ 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

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


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


def test_init_npy_tspace():
Expand Down Expand Up @@ -451,8 +448,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
29 changes: 13 additions & 16 deletions odl/test/test_doc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2018 The ODL contributors
# Copyright 2014-2020 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -16,26 +16,26 @@
"""

from __future__ import division

import doctest
from doctest import IGNORE_EXCEPTION_DETAIL, ELLIPSIS, NORMALIZE_WHITESPACE
import os
from doctest import ELLIPSIS, IGNORE_EXCEPTION_DETAIL, NORMALIZE_WHITESPACE

import numpy
import pytest

import odl
from odl.util.testutils import simple_fixture

try:
import matplotlib
matplotlib.use('Agg') # To avoid the backend freezing
matplotlib.use('agg') # prevent backend from freezing
import matplotlib.pyplot as plt
except ImportError:
pass

# Modules to be added to testing globals
import numpy
import odl
try:
import proximal
except ImportError:
proximal = None

doctest_extraglobs = {'odl': odl, 'np': numpy, 'proximal': proximal}
doctest_extraglobs = {'odl': odl, 'np': numpy}

root_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
os.pardir, os.pardir, 'doc', 'source')
Expand All @@ -55,13 +55,10 @@
doc_src_files.append(os.path.join(path, filename))


@pytest.fixture(scope="module", ids=doc_src_files, params=doc_src_files)
def doc_src_file(request):
return request.param
doc_src_file = simple_fixture("doc_src_file", doc_src_files)


@pytest.mark.skipif("not pytest.config.getoption('--doctest-doc')",
reason='Need --doctest-doc option to run')
@pytest.mark.suite("doc_doctests")
def test_file(doc_src_file):
# FIXXXME: This doesn't seem to actually test the file :-(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be TODO :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, new issue I guess

doctest.testfile(doc_src_file, module_relative=False, report=True,
Expand Down
17 changes: 8 additions & 9 deletions odl/test/test_examples.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 @@ -19,10 +19,14 @@
"""

from __future__ import division

import os
import pytest
import sys

import pytest

import odl
from odl.util.testutils import simple_fixture

try:
import matplotlib
Expand All @@ -36,23 +40,18 @@
# Make a fixture for all examples
here = os.path.dirname(os.path.abspath(__file__))
examples_path = os.path.join(here, os.path.pardir, os.path.pardir, 'examples')
example_ids = []
example_params = []
for dirpath, dirnames, filenames in os.walk(examples_path):
for filename in [f for f in filenames
if f.endswith('.py') and
not any(f.startswith(pre) for pre in ignore_prefix)]:
example_params.append(os.path.join(dirpath, filename))
example_ids.append(filename[:-3]) # skip .py


@pytest.fixture(scope="module", ids=example_ids, params=example_params)
def example(request):
return request.param
example = simple_fixture("example", example_params)


@pytest.mark.skipif("not pytest.config.getoption('--examples')",
reason='Need --examples option to run')
@pytest.mark.suite("examples")
def test_example(example):
if (sys.version_info.major, sys.version_info.minor) <= (3, 3):
# The `imp` module is deprecated since 3.4
Expand Down
Loading