Skip to content

Commit e703533

Browse files
authored
Merge pull request #94 from etas-contrib/feature/add-unittest-initial
feat(test): add unit test infrastructure with py_itf_unittest
2 parents 7aa37f8 + d04ec30 commit e703533

27 files changed

Lines changed: 248 additions & 73 deletions

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ common --registry=https://bcr.bazel.build
33

44
test --test_output=errors
55

6+
coverage --combined_report=lcov
7+
coverage --instrumentation_filter="//score/itf[/:]"
8+
69
build:x86_64-qnx --incompatible_strict_action_env
710
build:x86_64-qnx --platforms=@score_bazel_platforms//:x86_64-qnx-sdp_8.0.0-posix
811
build:x86_64-qnx --sandbox_writable_path=/var/tmp

.github/workflows/itf-qnx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
SCORE_QNX_USER: ${{ secrets.SCORE_QNX_USER }}
5959
SCORE_QNX_PASSWORD: ${{ secrets.SCORE_QNX_PASSWORD }}
6060
run: |
61-
bazel test --config=qemu-integration //test:qnx_qemu_tests \
61+
bazel test --config=qemu-integration //test/integration:qnx_qemu_tests \
6262
--credential_helper=*.qnx.com=${{ github.workspace }}/tools/qnx_credential_helper.py
6363
- name: Cleanup QNX License
6464
if: always()

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ python = use_extension("@rules_python//python/extensions:python.bzl", "python")
3434
python.defaults(python_version = DEFAULT_PYTHON_VERSION)
3535

3636
[python.toolchain(
37+
configure_coverage_tool = True,
3738
is_default = version == DEFAULT_PYTHON_VERSION,
3839
python_version = version,
3940
) for version in PYTHON_VERSIONS]

bazel/py_itf_unittest.bzl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
"""Lightweight macro for running unit tests via pytest without ITF plugin infrastructure."""
15+
16+
load("@rules_python//python:defs.bzl", "py_test")
17+
18+
def py_itf_unittest(name, srcs, deps = [], data = [], env = {}, pytest_config = None, **kwargs):
19+
"""Thin py_test wrapper for unit tests that do not need ITF plugin machinery.
20+
21+
Unlike py_itf_test, this macro creates a direct py_test with no launcher
22+
script or plugin infrastructure, so Bazel coverage works out of the box.
23+
24+
Args:
25+
name: Target name.
26+
srcs: Python test source files.
27+
deps: Additional Python dependencies.
28+
data: Data files available at runtime.
29+
env: Environment variables for the test.
30+
pytest_config: Optional pytest config file. Defaults to @score_itf//:pytest.ini.
31+
**kwargs: Forwarded to py_test (e.g. size, timeout, tags).
32+
"""
33+
pytest_bootstrap = Label("@score_itf//:main.py")
34+
if not pytest_config:
35+
pytest_config = Label("@score_itf//:pytest.ini")
36+
37+
py_test(
38+
name = name,
39+
srcs = [pytest_bootstrap] + srcs,
40+
main = pytest_bootstrap,
41+
args = [
42+
"-c $(location %s)" % pytest_config,
43+
"-p no:cacheprovider",
44+
"--show-capture=no",
45+
"--junitxml=$$XML_OUTPUT_FILE",
46+
] + ["$(location %s)" % x for x in srcs],
47+
deps = ["@score_itf//:itf", "@itf_pip//pytest_mock"] + deps,
48+
data = [pytest_config] + data,
49+
env = {"PYTHONDONOTWRITEBYTECODE": "1"} | env,
50+
**kwargs
51+
)

defs.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
"""ITF public Bazel interface"""
1414

1515
load("@score_itf//bazel:py_itf_test.bzl", local_py_itf_test = "py_itf_test")
16+
load("@score_itf//bazel:py_itf_unittest.bzl", local_py_itf_unittest = "py_itf_unittest")
1617

1718
py_itf_test = local_py_itf_test
19+
py_itf_unittest = local_py_itf_unittest

examples/examples/itf/test_dlt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../test/test_dlt.py
1+
../../../test/integration/test_dlt.py
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../test/test_docker.py
1+
../../../test/integration/test_docker.py

examples/examples/itf/test_qemu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../test/test_qemu.py
1+
../../../test/integration/test_qemu.py

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pytest==9.0.3
55
paramiko==4.0.0
66
typing-extensions==4.15.0
77
pydantic==2.10.6
8+
pytest-mock==3.14.0

requirements_lock_3_10.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ pynacl==1.6.2 \
505505
pytest==9.0.3 \
506506
--hash=sha256:2c5efc453d45394fdd706ade797c0a81091eccd1d6e4bccfcd476e2b8e0ab5d9 \
507507
--hash=sha256:b86ada508af81d19edeb213c681b1d48246c1a91d304c6c81a427674c17eb91c
508+
# via
509+
# -r requirements.in
510+
# pytest-mock
511+
pytest-mock==3.14.0 \
512+
--hash=sha256:0b72c38033392a5f4621342fe11e9219ac11ec9d375f8e2a0c164539e0d70f6f \
513+
--hash=sha256:2719255a1efeceadbc056d6bf3df3d1c5015530fb40cf347c0f9afac88410bd0
508514
# via -r requirements.in
509515
requests==2.33.0 \
510516
--hash=sha256:3324635456fa185245e24865e810cecec7b4caf933d7eb133dcde67d48cee69b \

0 commit comments

Comments
 (0)