Test plans in pytest-f3ts provide structure for organizing hardware tests into logical groups with shared configuration and execution order.
Anatomy of a Test#
A test evaluates whether system behavior matches expected results. The process breaks down into four stages:
-
Setup: Prepare everything needed for the test, including initializing hardware interfaces and configuring test equipment.
-
Act: The critical action that triggers the behavior being tested, altering the Device Under Test (DUT) state through signals, input parameter changes, or hardware function triggers.
-
Assert: Examine the resulting state post-action and assess whether it aligns with our expectations. This involves verifying outputs, checking protocols, and confirming circuit performance.
-
Teardown: Reset the test environment to prevent interference with subsequent tests by clearing states, data, or shutting down equipment.
Test Plan Structure#
A pytest-f3ts test plan consists of five key components:
config.yml#
Configuration file containing test limits, interface settings, and runner parameters to define customizable testing thresholds.
conftest.py#
Standard pytest configuration file defining the test interface fixture and other pytest-specific settings for hardware interaction.
test_plan.py#
Contains actual test case functions that leverage the defined interfaces and configurations to interact with hardware and verify outcomes.
interface.py#
Module defining the test interface for all instrumentation and hardware, encapsulating low-level hardware interactions.
pyproject.toml#
Project configuration for Poetry dependency management, listing packages required for the testing framework.
Creating a Test Plan#
Suggested Directory Structure#
Organize your test plan project with these key files:
fixture_controller_functional_test/
├── config.yml
├── conftest.py
├── test_plan.py
├── interface.py
└── pyproject.toml
Setup Steps#
- Create new project directory
- Run
poetry init - Add pytest-f3ts as a dependency via
poetry add pytest-f3ts - Create config.yml with test name
- Develop interface.py with TestInterface class
- Write test_plan.py with test cases
- Configure conftest.py with pytest fixtures
interface.py Template#
import logging
import os
class TestInterface:
def __init__(self):
"""Initialize test and measurement devices"""
pass
def close(self):
"""Teardown all hardware"""
passconftest.py Template#
import pytest
from interface import TestInterface
@pytest.fixture(scope="session")
def test_fixture(request):
"""Session-scoped fixture for hardware interface"""
interface = TestInterface()
def teardown():
interface.close()
request.addfinalizer(teardown)
return interfaceRunning Tests#
To run the test plan, use the following command:
poetry run pytest -p pytest_f3ts --config config.ymlExample Project#
An example project for FixturFab's FixturCtrl is available on GitLab for practical implementation guidance.