diff --git a/.github/workflows/run_tests_in_tox.yml b/.github/workflows/run_tests_in_tox.yml index 6290b09fb5c..b971fd80fd8 100644 --- a/.github/workflows/run_tests_in_tox.yml +++ b/.github/workflows/run_tests_in_tox.yml @@ -52,6 +52,8 @@ jobs: env: MLFLOW_TRACKING_SERVER_URI: ${{ vars.MLFLOW_TRACKING_SERVER_URI }} BENCHMARK_RESULTS_CLEAR: ${{ vars.BENCHMARK_RESULTS_CLEAR }} + GH_CTX_REF_NAME: ${{ github.ref_name }} + GH_CTX_SHA: ${{ github.sha }} run: tox -vv -e tests-${{ inputs.toxenv-task }}-${{ inputs.toxenv-pyver }}-${{ inputs.toxenv-ptver }} -- ${{ inputs.tests-dir }} - name: Upload test results uses: actions/upload-artifact@v3 diff --git a/tests/conftest.py b/tests/conftest.py index e0e6956e841..675d66778a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -98,13 +98,14 @@ def manage_tm_config_for_testing(): @pytest.fixture(autouse=True, scope="session") def init_mlflow_tracking(): - uri = os.environ.get("MLFLOW_TRACKING_SERVER_URI", "http://localhost:8080") - mlflow.set_tracking_uri(uri=uri) + uri = os.environ.get("MLFLOW_TRACKING_SERVER_URI") + if uri is not None: + mlflow.set_tracking_uri(uri=uri) yield @pytest.fixture(scope="session") def fxt_mlflow_client(): - uri = os.environ.get("MLFLOW_TRACKING_SERVER_URI", "http://localhost:8080") - return mlflow.MlflowClient(uri) + uri = os.environ.get("MLFLOW_TRACKING_SERVER_URI") + return mlflow.MlflowClient(uri) if uri is not None else None diff --git a/tests/perf/conftest.py b/tests/perf/conftest.py index 05d38e6ed1e..6fb181f5be4 100644 --- a/tests/perf/conftest.py +++ b/tests/perf/conftest.py @@ -5,7 +5,6 @@ import os import re import shutil -import subprocess from datetime import datetime from pathlib import Path from typing import Dict, List @@ -90,14 +89,16 @@ def fxt_output_root(request: pytest.FixtureRequest, tmp_path_factory: pytest.Tem if output_root is None: output_root = tmp_path_factory.mktemp("otx-benchmark") data_str = datetime.now().strftime("%Y%m%d-%H%M%S") - commit_str = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode("ascii").strip() - return Path(output_root) / (data_str + "-" + commit_str) + commit_str = os.environ.get("GH_CTX_SHA", "unknown") + print(f"Git SHA configured with {commit_str}") + return Path(output_root) / (data_str + "-" + commit_str[:7]) @pytest.fixture(scope="session") def fxt_working_branch() -> str: """Git branch name for the current HEAD.""" - branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode("ascii").strip() + branch = os.environ.get("GH_CTX_REF_NAME", "unknown") + print(f"working branch name fixture configured with {branch}") return branch @@ -241,6 +242,13 @@ def fxt_benchmark_summary(request: pytest.FixtureRequest, fxt_output_root: Path, all_results.to_csv(output_path, index=False) print(f" -> Saved to {output_path}.") + if fxt_mlflow_client is None: + print( + "Tracking server is not configured. for logging results, " + "set 'MLFLOW_TRACKING_SERVER_URI' environment variable to server URI ." + ) + return + # logging to the mlflow for 'develop' or 'releases/x.x.x' branch if fxt_working_branch == "develop" or bool(re.match("^releases/[0-9]+\.[0-9]+\.[0-9]+$", fxt_working_branch)): version = VERSION diff --git a/tox.ini b/tox.ini index aef83193ed0..6c7f7da2581 100644 --- a/tox.ini +++ b/tox.ini @@ -67,6 +67,8 @@ passenv = {[testenv]passenv} MLFLOW_TRACKING_SERVER_URI BENCHMARK_RESULTS_CLEAR + GH_CTX_REF_NAME + GH_CTX_SHA commands = python -m pytest -ra --showlocals --csv={toxworkdir}/{envname}.csv {posargs:tests/integration/{[testenv]test_dir}}