Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions .github/workflows/end2end_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,74 @@
cancel-in-progress: true

jobs:
run_tests:
name: E2E Tests on ${{ matrix.os }} / Python ${{ matrix.version }}
ubuntu_full:
name: E2E full on ubuntu-latest / Python ${{ matrix.version }} / shard ${{ matrix.shard }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
version: ['3.10']
shard: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Comment thread
coderabbitai[bot] marked this conversation as resolved.

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

Check failure on line 30 in .github/workflows/end2end_tests.yaml

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608`.
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v5

Check failure on line 37 in .github/workflows/end2end_tests.yaml

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608`.
with:
python-version: ${{ matrix.version }}
cache: pip

- name: Install dependencies
shell: bash
run: |
CONSTRAINTS_FILE="$GITHUB_WORKSPACE/constraints.txt"
echo "setuptools<82" > "$CONSTRAINTS_FILE"
export PIP_CONSTRAINT="$CONSTRAINTS_FILE"
pip install -e .[dev]

- name: Run full public tests
run: pytest tests/test_end2end.py --e2e-suite full --e2e-shard-index ${{ matrix.shard }} --e2e-shard-count 10 --download-weights -s -v

- name: Authenticate to Google Cloud
if: matrix.shard == 0 && github.event.pull_request.head.repo.full_name == github.repository
uses: google-github-actions/auth@v2

Check failure on line 55 in .github/workflows/end2end_tests.yaml

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608`.
with:
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
create_credentials_file: true
export_environment_variables: true

- name: Run private model tests
if: matrix.shard == 0 && github.event.pull_request.head.repo.full_name == github.repository
run: pytest tests/test_end2end.py::test_private_model_conversion --test-private --delete-weights-now -s -v

cross_platform_representative:
name: E2E representative on ${{ matrix.os }} / Python ${{ matrix.version }} / shard ${{ matrix.shard }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macOS-latest]
version: ['3.10']
shard: [0, 1]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4

Check failure on line 78 in .github/workflows/end2end_tests.yaml

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608`.
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
submodules: recursive # Ensures submodules are cloned
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v5

Check failure on line 85 in .github/workflows/end2end_tests.yaml

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608`.
with:
python-version: ${{ matrix.version }}
cache: pip
Expand All @@ -47,16 +95,17 @@
export PIP_CONSTRAINT="$CONSTRAINTS_FILE"
pip install -e .[dev]

- name: Run tests
run: pytest tests/test_end2end.py --download-weights --delete-weights-now -s -v
- name: Run representative public tests
run: pytest tests/test_end2end.py --e2e-suite representative --e2e-shard-index ${{ matrix.shard }} --e2e-shard-count 2 --download-weights -s -v

- name: Authenticate to Google Cloud
if: matrix.shard == 0 && github.event.pull_request.head.repo.full_name == github.repository
uses: google-github-actions/auth@v2

Check failure on line 103 in .github/workflows/end2end_tests.yaml

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608`.
Comment thread
rolandocortez marked this conversation as resolved.
with:
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
create_credentials_file: true
export_environment_variables: true

- name: Run private model tests
if: github.event.pull_request.head.repo.full_name == github.repository
if: matrix.shard == 0 && github.event.pull_request.head.repo.full_name == github.repository
run: pytest tests/test_end2end.py::test_private_model_conversion --test-private --delete-weights-now -s -v
8 changes: 4 additions & 4 deletions .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ jobs:
- name: Run tests with coverage [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
working-directory: ${{ inputs.tools_ref != '' && 'tools' || '' }}
env:
COVERAGE_PROCESS_START: .coveragerc
run: |
export COVERAGE_PROCESS_START="$PWD/.coveragerc"
export COVERAGE_FILE="$PWD/.coverage"
coverage erase
coverage run -m pytest tests/test_unittests.py --download-weights --delete-weights-now -s -v --junit-xml pytest.xml
coverage run -m pytest tests/test_unittests.py -n 2 --dist load --download-weights -s -v --junit-xml pytest.xml
coverage combine
coverage xml -o coverage.xml -i # Recent changes to coverage 7.13 make it stricter where it was previously passing https://coverage.readthedocs.io/en/7.13.0/messages.html#error-no-source


- name: Run tests [Windows, macOS]
if: matrix.os != 'ubuntu-latest' || matrix.version != '3.10'
working-directory: ${{ inputs.tools_ref != '' && 'tools' || '' }}
run: pytest tests/test_unittests.py --download-weights --delete-weights-now -s -v --junit-xml pytest.xml
run: pytest tests/test_unittests.py -n 2 --dist load --download-weights -s -v --junit-xml pytest.xml

- name: Generate coverage badge [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10' && inputs.tools_ref == '' && inputs.ml_ref == ''
Expand Down
6 changes: 3 additions & 3 deletions media/coverage_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pytest
pytest-xdist>=3.6.1
pytest-subtests
pre-commit>=4.1.0
pytest-cov>=4.1.0
Expand Down
8 changes: 4 additions & 4 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Unit tests download the preset weights from original repositories and check if t
If set then test only that specific yolo version
--test-case=TEST_CASE
If set then test only that specific test case
--delete-weights-now Clean weights after every test to save space - but longer test time.
--delete-weights-now Clean weights after every test to save disk space, at the cost of longer runtime.
```

Here is an example of the call to run:

```
pytest --download-weights --log-cli-level=INFO --log-file=out.log --log-file-level=DEBUG .
```bash
pytest tests/test_unittests.py -n 2 --dist load --download-weights --log-cli-level=INFO --log-file=out.log --log-file-level=DEBUG
```

This will run the full test suite on all the supported models and store the DEBUG logs into the out.log file.
This will run the full unit test suite on all supported models and store the DEBUG logs in the out.log file.
36 changes: 30 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
import os
import shutil
from pathlib import Path

import pytest

pytest_plugins = ["e2e_shards"]

logger = logging.getLogger()

os.environ.setdefault("LUXONIS_TELEMETRY_ENABLED", "false")
Expand Down Expand Up @@ -68,21 +71,42 @@ def test_config(pytestconfig):
}


@pytest.fixture(scope="session")
def test_workspace(tmp_path_factory, request) -> Path:
"""Create one isolated conversion workspace per pytest worker."""
worker_id = getattr(request.config, "workerinput", {}).get("workerid", "master")
workspace = tmp_path_factory.mktemp(f"tools-tests-{worker_id}")
(workspace / "weights").mkdir(exist_ok=True)
return workspace


def _artifact_path(request: pytest.FixtureRequest, name: str) -> Path:
"""Resolve cleanup paths without changing E2E behavior."""
if "test_workspace" in request.fixturenames:
workspace = request.getfixturevalue("test_workspace")
return Path(workspace) / name

return Path(name)


@pytest.fixture(scope="function", autouse=True)
def cleanup_output_after_tests(test_config):
def cleanup_output_after_tests(test_config, request):
yield # Tests run here
if test_config["delete_output"]:
folder_to_delete = "shared_with_container"
if os.path.exists(folder_to_delete):
folder_to_delete = _artifact_path(
request,
"shared_with_container",
)
if folder_to_delete.exists():
shutil.rmtree(folder_to_delete)
logger.info(f"Removed test artifacts from {folder_to_delete}")


@pytest.fixture(scope="function", autouse=True)
def cleanup_weights_after_tests(test_config):
def cleanup_weights_after_tests(test_config, request):
yield # Tests run here
if test_config["delete_weights_now"]:
folder_to_delete = "weights"
if os.path.exists(folder_to_delete):
folder_to_delete = _artifact_path(request, "weights")
if folder_to_delete.exists():
shutil.rmtree(folder_to_delete)
logger.info(f"Removed test artifacts from {folder_to_delete}")
Loading
Loading