Best Practices & Advanced Topics¶
This page covers recommended practices for test design, configuration, and security, followed by advanced patterns for custom fixtures, multi-device testing, Docker* integration, and iteration-level visualizations.
Best Practices¶
Test Design¶
- Follow the 7-step pattern — Maintain consistency across all tests. See Writing Tests.
- Use descriptive test IDs — Format:
{SUITE}-{NUM}(e.g.,VSN-001). - Leverage caching — Tests should work correctly both with and without cached results.
- Validate requirements early — Call
validate_system_requirements_from_configsbefore any setup work. - Use appropriate log levels — Log important steps at
INFO, debug details atDEBUG. - Handle cleanup — Always release resources (containers, processes, temp files) in
try/finallyblocks.
Configuration¶
- Define clear KPIs — Set realistic thresholds based on measured baselines.
- Use requirement flags — Prefer built-in flags over custom validation logic. See System Requirements.
- Version profiles — Include a
versionfield in all profile YAML files. - Organize profiles — Place in
qualifications/,suites/, orverticals/as appropriate.
Error Handling¶
- Use pytest mechanisms —
pytest.skip(),pytest.fail(),pytest.xfail()for controlled failure states. - Log errors with context — Include parameter values and suggested fixes in error messages.
- Attach diagnostics to Allure — Use Allure attachments for logs, screenshots, and config dumps.
Performance¶
- Cache expensive operations — Model downloads, format conversions, and compilations should be cached.
- Set appropriate timeouts — Use the
timeoutparameter in profiles; typical values are 180–600 seconds. - Parallelize multi-device tests — Use thread pools when running across multiple devices.
- Monitor resources — Track memory and storage usage when handling large models.
Security¶
- Validate user inputs — Use allow-lists for any user-provided values.
- Avoid
shell=True— Use list-based subprocess calls. - Set restrictive file permissions — Use
0o750or0o770. - Never log secrets — Keep tokens, passwords, and API keys out of log output.
Custom Fixtures¶
Create test-specific fixtures in a conftest.py file within the suite directory:
# src/esq/suites/my_domain/conftest.py
import pytest
@pytest.fixture(scope="session")
def shared_resource():
"""Shared across all tests in this suite."""
resource = setup_resource()
yield resource
cleanup_resource(resource)
@pytest.fixture
def test_specific_resource(request):
"""Created fresh for each test."""
return create_resource()
Multi-Device Testing¶
Run tests across multiple Intel® devices in parallel:
from concurrent.futures import ThreadPoolExecutor, as_completed
from sysagent.utils.system.ov_helper import get_available_devices_by_category
# Discover available devices
device_dict = get_available_devices_by_category(
device_categories=["cpu", "igpu", "dgpu"]
)
# Execute tests in parallel
with ThreadPoolExecutor(max_workers=len(device_dict)) as executor:
futures = {
executor.submit(run_test_on_device, device_id): device_id
for device_id in device_dict.keys()
}
for future in as_completed(futures):
device_id = futures[future]
try:
result = future.result()
results.metrics[f"throughput_{device_id}"] = Metrics(
value=result["throughput"],
unit="fps"
)
except Exception as e:
logger.error(f"Test failed on {device_id}: {e}")
Docker* Integration¶
Use Docker* for isolated test environments:
from sysagent.utils.infrastructure import DockerClient
docker_client = DockerClient()
# Build image
build_result = docker_client.build_image(
path=dockerfile_dir,
tag="my-test-image:latest",
nocache=False
)
# Run container
container_result = docker_client.run_container(
image="my-test-image:latest",
command=["python", "test_script.py"],
volumes={
"/host/path": {"bind": "/container/path", "mode": "rw"}
},
environment={"VAR": "value"},
timeout=300
)
output = container_result.get("output", "")
exit_code = container_result.get("exit_code", -1)
Custom Metrics and Aggregation¶
Aggregate results from multiple devices into a single summary metric:
def aggregate_device_metrics(device_results):
"""Aggregate metrics across multiple devices."""
total_throughput = sum(r["throughput"] for r in device_results.values())
avg_latency = sum(r["latency"] for r in device_results.values()) / len(device_results)
return {
"total_throughput": total_throughput,
"avg_latency": avg_latency,
"device_count": len(device_results)
}
# Store per-device metrics
for device_id, device_result in device_results.items():
results.metrics[f"throughput_{device_id}"] = Metrics(
value=device_result["throughput"],
unit="fps"
)
# Store aggregated metric as the key metric
aggregated = aggregate_device_metrics(device_results)
results.metrics["total_throughput"] = Metrics(
value=aggregated["total_throughput"],
unit="fps",
is_key_metric=True
)
Iteration Data and Visualizations¶
Track per-iteration metrics for detailed analysis and charts in the Allure report:
iteration_data = {
"iterations": [],
"throughput": [],
"latency": []
}
for i in range(num_iterations):
result = run_iteration()
iteration_data["iterations"].append(i)
iteration_data["throughput"].append(result["throughput"])
iteration_data["latency"].append(result["latency"])
# Pass iteration data to the summarizer to generate charts
summarize_test_results(
results=results,
test_name=test_name,
iteration_data=iteration_data,
enable_visualizations=True,
configs=configs,
get_kpi_config=get_kpi_config
)
Related Pages¶
- Writing Tests — Full step-by-step test creation guide
- Fixtures Reference — All available pytest fixtures
- System Requirements — Hardware and software requirement flags
- Allure Report Customization — Customizing the report UI