{"record":{"id":"281a1c1881ee1162","repo":"apache/beam","slug":"failed-assert-r","errorCode":null,"errorMessage":"Failed assert: [] == %r","messagePattern":"Failed assert: \\[\\] == %r","errorType":"exception","errorClass":"BeamAssertException","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/testing/util.py","lineNumber":298,"sourceCode":"  Args:\n    expected: A list of elements or hamcrest matchers to be used to match\n      the elements of a single PCollection.\n  \"\"\"\n  def _matches(actual):\n    from hamcrest.core import assert_that as hamcrest_assert\n    from hamcrest.library.collection import contains_inanyorder\n    expected_list = list(expected)\n\n    hamcrest_assert(actual, contains_inanyorder(*expected_list))\n\n  return _matches\n\n\ndef is_empty():\n  def _empty(actual):\n    actual = list(actual)\n    if actual:\n      raise BeamAssertException('Failed assert: [] == %r' % actual)\n\n  return _empty\n\n\ndef is_not_empty():\n  \"\"\"\n  This is test method which makes sure that the pcol is not empty and it has\n  some data in it.\n  :return:\n  \"\"\"\n  def _not_empty(actual):\n    actual = list(actual)\n    if not actual:\n      raise BeamAssertException('Failed assert: pcol is empty')\n\n  return _not_empty\n\n","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/testing/util.py#L280-L316","documentation":"The is_empty() matcher's _empty function converts the actual PCollection contents to a list and raises BeamAssertException if the list is non-empty, reporting that the empty list [] did not equal the actual elements. It asserts a pipeline stage produced zero output.","triggerScenarios":"assert_that(pcoll, is_empty()) where the pipeline emitted one or more elements — e.g. a filter intended to remove everything let some records through.","commonSituations":"Testing that invalid/filtered records are dropped; regression tests asserting no side outputs; overly permissive filter predicates; unexpected data in test input.","solutions":["Fix the upstream filter/transform so no elements pass through to the assertion.","If output is legitimately non-empty, replace is_empty() with equal_to(expected_elements).","Inspect the actual elements in the message to identify which records escaped filtering."],"exampleFix":"// before\nassert_that(pcoll, is_empty())  # pcoll has ['x']\n// after\nassert_that(pcoll, equal_to([]))  # or fix the filter upstream\n","handlingStrategy":"try-catch","validationCode":"# assert upstream filter predicate actually excludes all sample records\nassert all(not keep(record) for record in sample_input), 'filter leaks records'","typeGuard":null,"tryCatchPattern":"from apache_beam.testing.util import BeamAssertException\ntry:\n    assert_that(pcoll, is_empty())\nexcept BeamAssertException as e:\n    logging.error('Expected empty output, got elements: %s', e)\n    raise","preventionTips":["Unit-test the filter predicate directly before the pipeline test","Use is_empty only when the empty output is a hard contract; otherwise equal_to","Inspect the leaked elements printed in the message to refine the predicate"],"tags":["python","apache-beam","assertion","test","emptiness"],"backgroundTag":"assertion-failed","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"}