Skip to content

Commit

Permalink
Adds a cli arg to run_all_tests.py for testing a selected extension (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
jsmith-bdai authored Aug 2, 2024
1 parent de54e12 commit e90400b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tools/run_all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("--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("--extension", type=str, default=None, help="Run tests only for the given extension.")
# parse arguments
args = parser.parse_args()
return args
Expand All @@ -83,6 +84,7 @@ def test_all(
per_test_timeouts: dict[str, float] = {},
discover_only: bool = False,
quiet: bool = False,
extension: str | None = None,
) -> bool:
"""Run all tests under the given directory.
Expand All @@ -96,7 +98,8 @@ def test_all(
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).
Defaults to False.
extension: Run tests only for the given extension. Defaults to None, which means all extensions'
tests will be run.
Returns:
True if all un-skipped tests pass or `discover_only` is True. Otherwise, False.
Expand Down Expand Up @@ -126,6 +129,23 @@ def test_all(
break
else:
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
if len(tests_to_skip) != 0:
for test_path in all_test_paths:
Expand Down Expand Up @@ -303,6 +323,7 @@ def test_all(
per_test_timeouts=PER_TEST_TIMEOUTS,
discover_only=args.discover_only,
quiet=args.quiet,
extension=args.extension,
)
# update exit status based on all tests passing or not
if not test_success:
Expand Down

0 comments on commit e90400b

Please sign in to comment.