Skip to content

Commit d68510e

Browse files
committed
feat(test): add py_itf_unittest rule and restructure test directory
- Introduce py_itf_unittest macro: lightweight py_test wrapper with no ITF plugin infrastructure, pytest-mock included by default - Export py_itf_unittest via defs.bzl alongside py_itf_test - Move existing tests to test/integration/ - Add test/unit/ with test_ping (mocker) and test_qemu_config_schema (pure Pydantic model validation, no file I/O) - Add integration-level test_qemu_config_schema (load_configuration with real JSON files) and test_attribute_plugin - Set coverage instrumentation filter to //score/itf[/:]
1 parent 57728b1 commit d68510e

20 files changed

Lines changed: 224 additions & 70 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

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

test/BUILD renamed to test/integration/BUILD

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212
# *******************************************************************************
1313
load("//:defs.bzl", "py_itf_test")
1414

15+
py_itf_test(
16+
name = "test_attribute_plugin",
17+
srcs = ["test_attribute_plugin.py"],
18+
deps = ["//score/itf/plugins:attribute_plugin"],
19+
)
20+
21+
py_itf_test(
22+
name = "test_qemu_config_schema",
23+
srcs = ["test_qemu_config_schema.py"],
24+
data = [
25+
"//test/resources:qemu_bridge_config",
26+
"//test/resources:qemu_port_forwarding_config",
27+
],
28+
deps = [
29+
"//score/itf/plugins/qemu",
30+
"@rules_python//python/runfiles",
31+
],
32+
)
33+
1534
py_itf_test(
1635
name = "test_rules_are_working_correctly",
1736
srcs = [
@@ -183,35 +202,3 @@ test_suite(
183202
":test_ssh_configurable",
184203
],
185204
)
186-
187-
py_itf_test(
188-
name = "test_ping",
189-
srcs = [
190-
"test_ping.py",
191-
],
192-
)
193-
194-
py_itf_test(
195-
name = "test_qemu_config_schema",
196-
srcs = [
197-
"test_qemu_config_schema.py",
198-
],
199-
data = [
200-
"//test/resources:qemu_bridge_config",
201-
"//test/resources:qemu_port_forwarding_config",
202-
],
203-
deps = [
204-
"//score/itf/plugins/qemu",
205-
"@rules_python//python/runfiles",
206-
],
207-
)
208-
209-
py_itf_test(
210-
name = "test_attribute_plugin",
211-
srcs = [
212-
"test_attribute_plugin.py",
213-
],
214-
plugins = [
215-
"//score/itf/plugins:attribute_plugin",
216-
],
217-
)

0 commit comments

Comments
 (0)