Unverified Commit e90400b7 authored by James Smith's avatar James Smith Committed by GitHub

Adds a cli arg to `run_all_tests.py` for testing a selected extension (#753)

# Description

Add a cli argument `--extension` to run only unit tests for a selected
extension. As an example:

```bash
isaaclab -t --extension omni.isaac.lab_assets # Only runs tests under omni.isaac.lab_assets
```

Fixes #752 

## Type of change

- New feature (non-breaking change which adds functionality)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
parent de54e129
...@@ -70,6 +70,7 @@ def parse_args() -> argparse.Namespace: ...@@ -70,6 +70,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--discover_only", action="store_true", help="Only discover and print tests, don't run them.") parser.add_argument("--discover_only", action="store_true", help="Only discover and print tests, don't run them.")
parser.add_argument("--quiet", action="store_true", help="Don't print to console, only log to file.") parser.add_argument("--quiet", action="store_true", help="Don't print to console, only log to file.")
parser.add_argument("--timeout", type=int, default=DEFAULT_TIMEOUT, help="Timeout for each test in seconds.") parser.add_argument("--timeout", type=int, default=DEFAULT_TIMEOUT, help="Timeout for each test in seconds.")
parser.add_argument("--extension", type=str, default=None, help="Run tests only for the given extension.")
# parse arguments # parse arguments
args = parser.parse_args() args = parser.parse_args()
return args return args
...@@ -83,6 +84,7 @@ def test_all( ...@@ -83,6 +84,7 @@ def test_all(
per_test_timeouts: dict[str, float] = {}, per_test_timeouts: dict[str, float] = {},
discover_only: bool = False, discover_only: bool = False,
quiet: bool = False, quiet: bool = False,
extension: str | None = None,
) -> bool: ) -> bool:
"""Run all tests under the given directory. """Run all tests under the given directory.
...@@ -96,7 +98,8 @@ def test_all( ...@@ -96,7 +98,8 @@ def test_all(
discover_only: If True, only discover and print the tests without running them. Defaults to False. discover_only: If True, only discover and print the tests without running them. Defaults to False.
quiet: If False, print the output of the tests to the terminal console (in addition to the log file). quiet: If False, print the output of the tests to the terminal console (in addition to the log file).
Defaults to False. Defaults to False.
extension: Run tests only for the given extension. Defaults to None, which means all extensions'
tests will be run.
Returns: Returns:
True if all un-skipped tests pass or `discover_only` is True. Otherwise, False. True if all un-skipped tests pass or `discover_only` is True. Otherwise, False.
...@@ -126,6 +129,23 @@ def test_all( ...@@ -126,6 +129,23 @@ def test_all(
break break
else: else:
raise ValueError(f"Test to skip '{test_to_skip}' not found in tests.") raise ValueError(f"Test to skip '{test_to_skip}' not found in tests.")
# Filter tests by extension
if extension is not None:
all_tests_in_selected_extension = []
for test_path in all_test_paths:
# Extract extension name from test path
extension_name = test_path[test_path.find("extensions") :].split("/")[1]
# Skip tests that are not in the selected extension
if extension_name != extension:
continue
all_tests_in_selected_extension.append(test_path)
all_test_paths = all_tests_in_selected_extension
# Remove tests to skip from the list of tests to run # Remove tests to skip from the list of tests to run
if len(tests_to_skip) != 0: if len(tests_to_skip) != 0:
for test_path in all_test_paths: for test_path in all_test_paths:
...@@ -303,6 +323,7 @@ if __name__ == "__main__": ...@@ -303,6 +323,7 @@ if __name__ == "__main__":
per_test_timeouts=PER_TEST_TIMEOUTS, per_test_timeouts=PER_TEST_TIMEOUTS,
discover_only=args.discover_only, discover_only=args.discover_only,
quiet=args.quiet, quiet=args.quiet,
extension=args.extension,
) )
# update exit status based on all tests passing or not # update exit status based on all tests passing or not
if not test_success: if not test_success:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment