From bfc79217a8837b6615209fd0e530b3fe004921ef Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 13 Mar 2025 23:25:15 -0400 Subject: [PATCH] chore: Add ./scripts/unit-tests.sh (#1515) # What does this PR do? Useful for local development. Now you can just trigger the script and not care about specific arguments to pass to run unit tests. [//]: # (If resolving an issue, uncomment and update the line below) [//]: # (Closes #[issue-number]) ## Test Plan ``` $ . ./venv/bin/activate $ ./scripts/run_tests.sh $ echo $? 0 ``` [//]: # (## Documentation) Signed-off-by: Ihar Hrachyshka Co-authored-by: Nathan Weinberg <31703736+nathan-weinberg@users.noreply.github.com> --- .github/workflows/unit-tests.yml | 2 +- CONTRIBUTING.md | 16 ++++++++++++++++ scripts/unit-tests.sh | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 scripts/unit-tests.sh diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 517b5c39a..c7a30e9b8 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -33,7 +33,7 @@ jobs: - name: Run unit tests run: | - uv run --python ${{ matrix.python }} --with-editable . --with-editable ".[dev]" --with-editable ".[unit]" pytest --cov=llama_stack -s -v tests/unit/ --junitxml=pytest-report-${{ matrix.python }}.xml --cov-report=html:htmlcov-${{ matrix.python }} + PYTHON_VERSION=${{ matrix.python }} ./scripts/unit-tests.sh --cov=llama_stack --junitxml=pytest-report-${{ matrix.python }}.xml --cov-report=html:htmlcov-${{ matrix.python }} - name: Upload test results if: always() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 71e610064..1f188f259 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -108,6 +108,22 @@ uv run pre-commit run --all-files > [!CAUTION] > Before pushing your changes, make sure that the pre-commit hooks have passed successfully. +## Running unit tests + +You can run the unit tests by running: + +```bash +source .venv/bin/activate +./scripts/unit-tests.sh +``` + +If you'd like to run for a non-default version of Python (currently 3.10), pass `PYTHON_VERSION` variable as follows: + +``` +source .venv/bin/activate +PYTHON_VERSION=3.13 ./scripts/unit-tests.sh +``` + ## Adding a new dependency to the project To add a new dependency to the project, you can use the `uv` command. For example, to add `foo` to the project, you can run: diff --git a/scripts/unit-tests.sh b/scripts/unit-tests.sh new file mode 100755 index 000000000..dbc25e06b --- /dev/null +++ b/scripts/unit-tests.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the terms described in the LICENSE file in +# the root directory of this source tree. + +PYTHON_VERSION=${PYTHON_VERSION:-3.10} + +command -v uv >/dev/null 2>&1 || { echo >&2 "uv is required but it's not installed. Exiting."; exit 1; } + +uv python find $PYTHON_VERSION +FOUND_PYTHON=$? +if [ $FOUND_PYTHON -ne 0 ]; then + uv python install $PYTHON_VERSION +fi + +uv run --python $PYTHON_VERSION --with-editable . --with-editable ".[dev]" --with-editable ".[unit]" pytest -s -v tests/unit/ $@