Skip to content

Commit

Permalink
ci: added support for running individual test files (OSOceanAcoustics…
Browse files Browse the repository at this point in the history
…#1166)

Added a support for testing individual test files also instead of having support for testing only subpackages.
  • Loading branch information
praneethratna authored and ruxandra-valcu committed Sep 25, 2023
1 parent 20cb486 commit a949c5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
19 changes: 11 additions & 8 deletions .ci_helpers/run-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,20 @@ the latter via `minio <https://minio.io>`_.
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``

Expand Down

0 comments on commit a949c5b

Please sign in to comment.