{"record":{"id":"bff9a9ae1b2937be","repo":"apache/beam","slug":"failed-assert-nothing-matches-the-criterion","errorCode":null,"errorMessage":"Failed assert: nothing matches the criterion","messagePattern":"Failed assert: nothing matches the criterion","errorType":"exception","errorClass":"BeamAssertException","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/testing/util.py","lineNumber":444,"sourceCode":"  # similar to assert_that, we choose a label if it already exists.\n  if label in pipeline.applied_labels:\n    label_idx = 2\n    while f\"{label}_{label_idx}\" in pipeline.applied_labels:\n      label_idx += 1\n    label = f\"{label}_{label_idx}\"\n\n  def _apply_criterion(\n      e=DoFn.ElementParam,\n      t=DoFn.TimestampParam,\n      w=DoFn.WindowParam,\n      p=DoFn.PaneInfoParam):\n    if criterion(e, t, w, p):\n      return e, t, w, p\n\n  def _not_empty(actual):\n    actual = list(actual)\n    if not actual:\n      raise BeamAssertException('Failed assert: nothing matches the criterion')\n\n  result = input | label >> Map(_apply_criterion) | label + \"_filter\" >> Filter(\n      lambda e: e is not None)\n  assert_that(result, _not_empty)\n\n\ndef open_shards(glob_pattern, mode='rt', encoding='utf-8'):\n  \"\"\"Returns a composite file of all shards matching the given glob pattern.\n\n  Args:\n    glob_pattern (str): Pattern used to match files which should be opened.\n    mode (str): Specify the mode in which the file should be opened. For\n                available modes, check io.open() documentation.\n    encoding (str): Name of the encoding used to decode or encode the file.\n                    This should only be used in text mode.\n\n  Returns:\n    A stream with the contents of the opened files.","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/testing/util.py#L426-L462","documentation":"BeamAssertException raised by a `_not_empty` matcher attached to a filtered pipeline (`_apply_criterion` + `Filter` pipeline in the source) when no element matched the criterion, leaving the filtered output PCollection empty. It signals that the test expected at least one element satisfying the criterion but got none.","triggerScenarios":"Running the criterion-test pipeline (`input | label >> Map(_apply_criterion) | Filter(...)`) with data where the criterion function returns false for every element, so `assert_that(result, _not_empty)` fails.","commonSituations":"Testing combiners/criteria (e.g. in combiner property tests) with inputs that don't satisfy the predicate; a criterion that is too strict; test fixtures lacking suitable data.","solutions":["Verify the criterion logic — loosen it or fix bugs so at least one element matches.","Add test input that is guaranteed to satisfy the criterion.","Print/count elements before the Filter to see whether the input or the predicate is the problem."],"exampleFix":"// before\nresult = input | label >> Map(_apply_criterion) | label + \"_filter\" >> Filter(lambda e: e is not None)\nassert_that(result, _not_empty)\n// after\n# add an element guaranteed to match\ncriterion_input = input + [element_matching_criterion]","handlingStrategy":"validation","validationCode":"# ensure test input contains an element satisfying the criterion\nassert any(criterion(e) for e in input_elements), 'test input lacks matching element'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanity-check criterion functions on test data before pipeline runs","Include at least one element known to satisfy the criterion in test fixtures","Count pre-filter elements when tests fail"],"tags":["apache-beam","testing","assertion","filter"],"backgroundTag":"empty-result-set","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}