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 to Unit objects for the current cluster (based on --cluster-kind)
  • mgmt_enabled_units — a dict mapping unit names to Unit objects for the management cluster
  • unit_is_enabled — a callable that returns True if a unit is enabled in the current cluster
  • mgmt_unit_is_enabled — a callable that returns True if 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 the sylva-units.unit label)
  • 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 against
  • autouse — if True, automatically applies to all tests in the file/directory
  • fixture_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

Merge request reports

Loading