From a949c5b58422df1afe1be2b56c2e4c2820390e45 Mon Sep 17 00:00:00 2001 From: Praneeth Ratna <63547155+praneethratna@users.noreply.github.com> Date: Tue, 19 Sep 2023 22:27:55 +0530 Subject: [PATCH] ci: added support for running individual test files (#1166) Added a support for testing individual test files also instead of having support for testing only subpackages. --- .ci_helpers/run-test.py | 19 +++++++++++-------- docs/source/contributing.rst | 9 ++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.ci_helpers/run-test.py b/.ci_helpers/run-test.py index bd8c0435b6..fddb3622f8 100644 --- a/.ci_helpers/run-test.py +++ b/.ci_helpers/run-test.py @@ -118,15 +118,18 @@ for k, v in test_to_run.items(): print(f"=== RUNNING {k.upper()} TESTS===") print(f"Touched files: {','.join([os.path.basename(p) for p in v])}") - if k == "root": - file_glob_str = "echopype/tests/test_*.py" - cov_mod_arg = ["--cov=echopype"] + if all(os.path.exists(f) for f in v): + test_files = [str(p) for p in v] else: - file_glob_str = f"echopype/tests/{k}/*.py" - cov_mod_arg = [f"--cov=echopype/{k}"] - if args.include_cov: - pytest_args = original_pytest_args + cov_mod_arg - test_files = glob.glob(file_glob_str) + if k == "root": + file_glob_str = "echopype/tests/test_*.py" + cov_mod_arg = ["--cov=echopype"] + else: + file_glob_str = f"echopype/tests/{k}/*.py" + cov_mod_arg = [f"--cov=echopype/{k}"] + if args.include_cov: + pytest_args = original_pytest_args + cov_mod_arg + test_files = glob.glob(file_glob_str) final_args = pytest_args + test_files print(f"Pytest args: {final_args}") exit_code = pytest.main(final_args) diff --git a/docs/source/contributing.rst b/docs/source/contributing.rst index b4ac505dea..e8f6f8f944 100644 --- a/docs/source/contributing.rst +++ b/docs/source/contributing.rst @@ -145,13 +145,20 @@ the latter via `minio `_. will execute all tests. The entire test suite can be a bit slow, taking up to 40 minutes or more. If your changes impact only some of the subpackages (``convert``, ``calibrate``, ``preprocess``, etc), you can run ``run-test.py`` with only a subset of tests by passing -as an argument a comma-separated list of the modules that have changed. For example: +as an argument a comma-separated list of the modules that have changed or also run only particular test +files by passing a comma-separated list of test files that you want to run. For example: .. code-block:: bash python .ci_helpers/run-test.py --local --pytest-args="-vv" echopype/calibrate/calibrate_ek.py,echopype/preprocess/noise_est.py will run only tests associated with the ``calibrate`` and ``preprocess`` subpackages. + +.. code-block:: bash + + python .ci_helpers/run-test.py --local --pytest-args="-vv" echopype/tests/convert/test_convert_azfp.py,echopype/tests/clean/test_noise.py + +will run only the tests in the ``test_convert_azfp.py`` and ``test_noise.py`` files. For ``run-test.py`` usage information, use the ``-h`` argument: ``python .ci_helpers/run-test.py -h``