diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index d92711d285..d319a32ca4 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -137,6 +137,9 @@ This document explains the changes made to Iris for this release #. `@lbdreyer`_ and `@trexfeathers`_ (reviewer) removed the ``--coding-tests`` option from Iris' test runner. (:pull:`4765`) +#. `@lbdreyer`_ removed the Iris TestRunner. Tests are now run via nox or + pytest. (:pull:`5205`) + .. comment Whatsnew author names (@github name) in alphabetical order. Note that, diff --git a/lib/iris/config.py b/lib/iris/config.py index 3659ac7dcd..79d141e53f 100644 --- a/lib/iris/config.py +++ b/lib/iris/config.py @@ -171,8 +171,7 @@ def get_dir_option(section, option, default=None): ) # Override the data repository if the appropriate environment variable -# has been set. This is used in setup.py in the TestRunner command to -# enable us to simulate the absence of external data. +# has been set. override = os.environ.get("OVERRIDE_TEST_DATA_REPOSITORY") if override: TEST_DATA_DIR = None diff --git a/lib/iris/tests/runner/__init__.py b/lib/iris/tests/runner/__init__.py deleted file mode 100644 index b561e1cf87..0000000000 --- a/lib/iris/tests/runner/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Iris contributors -# -# This file is part of Iris and is released under the LGPL license. -# See COPYING and COPYING.LESSER in the root of the repository for full -# licensing details. -""" -Empty file to allow import. - -""" diff --git a/lib/iris/tests/runner/__main__.py b/lib/iris/tests/runner/__main__.py deleted file mode 100644 index 9f9c51c1f7..0000000000 --- a/lib/iris/tests/runner/__main__.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright Iris contributors -# -# This file is part of Iris and is released under the LGPL license. -# See COPYING and COPYING.LESSER in the root of the repository for full -# licensing details. -""" -Provides testing capabilities for installed copies of Iris. - -""" - -import argparse - -from ._runner import TestRunner - -parser = argparse.ArgumentParser( - "iris.tests", description=TestRunner.description -) -for long_opt, short_opt, help_text in TestRunner.user_options: - long_opt = long_opt.strip("=") - if long_opt in TestRunner.boolean_options: - parser.add_argument( - "--" + long_opt, - "-" + short_opt, - action="store_true", - help=help_text, - ) - else: - parser.add_argument("--" + long_opt, "-" + short_opt, help=help_text) -args = parser.parse_args() - -runner = TestRunner() - -runner.initialize_options() -for long_opt, short_opt, help_text in TestRunner.user_options: - arg = long_opt.replace("-", "_").strip("=") - setattr(runner, arg, getattr(args, arg)) -runner.finalize_options() - -runner.run() diff --git a/lib/iris/tests/runner/_runner.py b/lib/iris/tests/runner/_runner.py deleted file mode 100644 index 7f9439d4b6..0000000000 --- a/lib/iris/tests/runner/_runner.py +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright Iris contributors -# -# This file is part of Iris and is released under the LGPL license. -# See COPYING and COPYING.LESSER in the root of the repository for full -# licensing details. -""" -Provides testing capabilities for installed copies of Iris. - -""" - -# Because this file is imported by setup.py, there may be additional runtime -# imports later in the file. -import os -import sys - - -# NOTE: Do not inherit from object as distutils does not like it. -class TestRunner: - """Run the Iris tests under pytest and pytest-xdist for performance""" - - description = ( - "Run tests under pytest and pytest-xdist for performance. " - "Default behaviour is to run all non-gallery tests. " - "Specifying one or more test flags will run *only* those " - "tests." - ) - user_options = [ - ( - "no-data", - "n", - "Override the paths to the data repositories so it " - "appears to the tests that it does not exist.", - ), - ("stop", "x", "Stop running tests after the first error or failure."), - ("system-tests", "s", "Run the limited subset of system tests."), - ("gallery-tests", "e", "Run the gallery code tests."), - ("default-tests", "d", "Run the default tests."), - ( - "num-processors=", - "p", - "The number of processors used for running " "the tests.", - ), - ("create-missing", "m", "Create missing test result files."), - ("coverage", "c", "Enable coverage testing"), - ] - boolean_options = [ - "no-data", - "system-tests", - "stop", - "gallery-tests", - "default-tests", - "create-missing", - "coverage", - ] - - def initialize_options(self): - self.no_data = False - self.stop = False - self.system_tests = False - self.gallery_tests = False - self.default_tests = False - self.num_processors = None - self.create_missing = False - self.coverage = False - - def finalize_options(self): - # These environment variables will be propagated to all the - # processes that pytest-xdist creates. - if self.no_data: - print("Running tests in no-data mode...") - import iris.config - - iris.config.TEST_DATA_DIR = None - if self.create_missing: - os.environ["IRIS_TEST_CREATE_MISSING"] = "true" - - tests = [] - if self.system_tests: - tests.append("system") - if self.default_tests: - tests.append("default") - if self.gallery_tests: - tests.append("gallery") - if not tests: - tests.append("default") - print("Running test suite(s): {}".format(", ".join(tests))) - if self.stop: - print("Stopping tests after the first error or failure") - if self.num_processors is None: - self.num_processors = "auto" - else: - self.num_processors = int(self.num_processors) - - def run(self): - import pytest - - if hasattr(self, "distribution") and self.distribution.tests_require: - self.distribution.fetch_build_eggs(self.distribution.tests_require) - - tests = [] - if self.system_tests: - tests.append("lib/iris/tests/system_test.py") - if self.default_tests: - tests.append("lib/iris/tests") - if self.gallery_tests: - import iris.config - - default_doc_path = os.path.join(sys.path[0], "docs") - doc_path = iris.config.get_option( - "Resources", "doc_dir", default=default_doc_path - ) - gallery_path = os.path.join(doc_path, "gallery_tests") - if os.path.exists(gallery_path): - tests.append(gallery_path) - else: - print( - "WARNING: Gallery path %s does not exist." % (gallery_path) - ) - if not tests: - tests.append("lib/iris/tests") - - args = [ - None, - f"-n={self.num_processors}", - ] - - if self.stop: - args.append("-x") - - if self.coverage: - args.extend(["--cov=lib/iris", "--cov-report=xml"]) - - result = True - for test in tests: - args[0] = test - print() - print( - f"Running test discovery on {test} with {self.num_processors} processors." - ) - retcode = pytest.main(args=args) - result &= retcode.value == 0 - if result is False: - exit(1) diff --git a/noxfile.py b/noxfile.py index c7b0a0e05b..f4d135de92 100755 --- a/noxfile.py +++ b/noxfile.py @@ -188,13 +188,13 @@ def tests(session: nox.sessions.Session): session.install("--no-deps", "--editable", ".") session.env.update(ENV) run_args = [ - "python", - "-m", - "iris.tests.runner", - "--default-tests", + "pytest", + "-n", + "auto", + "lib/iris/tests", ] if "-c" in session.posargs or "--coverage" in session.posargs: - run_args.append("--coverage") + run_args[-1:-1] = ["--cov=lib/iris", "--cov-report=xml"] session.run(*run_args) @@ -241,10 +241,10 @@ def gallery(session: nox.sessions.Session): session.install("--no-deps", "--editable", ".") session.env.update(ENV) session.run( - "python", - "-m", - "iris.tests.runner", - "--gallery-tests", + "pytest", + "-n", + "auto", + "docs/gallery_tests", )