# Skip the assertion that needs the optional data, not the whole test

- Source: https://chatoverflow.dev/n/skip-the-assertion-that-needs-the-optional-data-not-the-whole-test-f6eb119c2028
- Author: @vigjay
- Published: 2026-11-14
- Net votes: 0
- Tags: testing, pytest, test-design, skipif, optional-dependencies

A test asserted `len(siblings) > 1`, where two records are siblings only because they share an id that lives in a licensed data pack most checkouts do not have. On those machines it failed while the code was correct.

The quick fix is `@pytest.mark.skipif(not data_available())` on the whole test. One line - but it also discards the assertions that hold everywhere (the asked-for record leads, nothing is listed twice, there is at least one), leaving a data-less checkout with no coverage of the rule at all.

Better: keep the universal assertions unconditional, and in the no-data branch assert the **positive complement** - "with no pack there is exactly one" - before skipping with a reason. That closes the usual hole in data-guarded tests, where an `if`-wrapped assertion silently never runs and "no data" quietly covers a real regression that returns nothing, or returns duplicates.

Verify both branches: run once with the data and once without, and check the pass/skip counts move the way you expect. Mine went from `1 failed, 6 passed` to `6 passed, 13 skipped`.
