RequiresTm1
from skipcheck_tm1_testcontainers import RequiresTm1Used in the walkthrough Test your code against a real TM1.
Runs a test class or method against a real TM1 server, and skips it when there isn't one.
Tests are skipped, not failed, when Docker isn't available or no
Tm1Source is configured, so a build without IBM software (such as GitHub CI)
stays green. A source that is configured but wrong, such as a folder with no TM1 in it,
fails instead.
Declare a Tm1ServerContainer parameter on a test method, constructor or
lifecycle method to get the shared container,
started on first use.
Tests share one server, so each test should create its own uniquely named objects and delete them afterwards. A test class that sets up a client once and cleans up after each test:
# Every test in the module needs TM1, and is skipped without one
pytestmark = pytest.mark.requires_tm1
# One client per module, on the shared server
@pytest.fixture(scope="module")
def tm1(tm1_server: Tm1ServerContainer) -> Iterator[Tm1Client]:
with Tm1Client.builder().base_url(tm1_server.rest_url).basic_auth(tm1_server.username, tm1_server.password).build() as client:
yield client
# The server is shared, so use a unique name and delete it afterwards
@pytest.fixture
def region(tm1: Tm1Client) -> Iterator[str]:
name = f"Region-{uuid.uuid4()}"
yield name
try:
tm1.dimensions.delete(name)
except Tm1Error:
pass
def test_creates_the_regions(tm1: Tm1Client, region: str) -> None:
north = ElementPatch.builder().name("North").type(ElementType.NUMERIC).build()
south = ElementPatch.builder().name("South").type(ElementType.NUMERIC).build()
hierarchy = HierarchyPatch.builder().name(region).elements([north, south]).build()
created = tm1.dimensions.create(DimensionPatch.builder().name(region).hierarchies([hierarchy]).build())
assert created.name == region
A test that only applies to some TM1 versions checks the server's and skips:
@pytest.mark.requires_tm1
def test_needs_a_recent_server(tm1_server: Tm1ServerContainer) -> None:
# Skips, rather than fails, on servers older than the feature
introduced_in = Tm1Version.parse("11.8.03000")
if not tm1_server.tm1_version.is_at_least(introduced_in):
pytest.skip(f"needs TM1 {introduced_in} or newer")
# ...
Members
NO_SOURCE_MESSAGE static | Why tests skip when no source is configured, and what to set. |
mark property |
NO_SOURCE_MESSAGE
staticNO_SOURCE_MESSAGEWhy tests skip when no source is configured, and what to set.
mark
propertymark