Add units fixture
Unit Fixtures
The framework provides fixtures for working with Sylva units deployed in your cluster. Units are identified by the sylva-units.unit label on Flux Kustomizations.
Session-Scoped Fixtures
enabled_units— a dict mapping unit names toUnitobjects for the current cluster (based on--cluster-kind)mgmt_enabled_units— a dict mapping unit names toUnitobjects for the management clusterunit_is_enabled— a callable that returnsTrueif a unit is enabled in the current clustermgmt_unit_is_enabled— a callable that returnsTrueif a unit is enabled in the management cluster
def test_units_enabled(enabled_units, unit_is_enabled):
assert "cluster" in enabled_units
assert unit_is_enabled("cluster")Unit Dataclass
Each unit is represented by a Unit object with the following attributes:
name— the unit name (from thesylva-units.unitlabel)kustomization_name— the name of the Flux Kustomization resource
def test_unit_details(cluster_unit):
print(f"Unit: {cluster_unit.name}")
print(f"Kustomization: {cluster_unit.kustomization_name}")Decorators
Use unit_fixture and mgmt_unit_fixture to create fixtures that automatically skip or fail if the unit is not enabled:
from sylva_test_framework.pytest_plugin.units import unit_fixture, mgmt_unit_fixture
@unit_fixture("cluster")
def cluster_unit(): ...
@mgmt_unit_fixture("cluster")
def mgmt_cluster_unit(): ...
def test_with_unit(cluster_unit):
assert cluster_unit.name == "cluster"Parameters:
unit_name— the unit name to check againstautouse— ifTrue, automatically applies to all tests in the file/directoryfixture_name— custom name for the fixture (defaults to the function name)on_disabled— action when unit is not enabled:"skip"(default) or"fail"
# Fail the test instead of skipping
@unit_fixture("my-unit", on_disabled="fail")
def my_unit(): ...
# Autouse: skip all tests in this file if unit is disabled
@unit_fixture("cluster", autouse=True)
def cluster_unit(): ...Edited by Jonathan GAYVALLET