{"record":{"id":"d19629003f9f1a6b","repo":"apache/beam","slug":"tests-attribute-must-be-a-list-of-test-specifications","errorCode":null,"errorMessage":"tests attribute must be a list of test specifications.","messagePattern":"tests attribute must be a list of test specifications\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/main.py","lineNumber":183,"sourceCode":"  pipeline_spec = yaml.load(pipeline_yaml, Loader=yaml_transform.SafeLineLoader)\n  options = _build_pipeline_options(pipeline_spec, pipeline_args)\n\n  if known_args.create_test and known_args.fix_tests:\n    raise ValueError(\n        'At most one of --create_test and --fix_tests may be specified.')\n  elif known_args.create_test:\n    result = unittest.TestResult()\n    tests = []\n  else:\n    if known_args.test_suite:\n      with open(known_args.test_suite) as fin:\n        test_suite_holder = yaml.load(\n            fin, Loader=yaml_transform.SafeLineLoader) or {}\n    else:\n      test_suite_holder = pipeline_spec\n    test_specs = test_suite_holder.get('tests', [])\n    if not isinstance(test_specs, list):\n      raise TypeError('tests attribute must be a list of test specifications.')\n    elif not test_specs:\n      raise RuntimeError(\n          'No tests found. '\n          \"If you haven't added a set of tests yet, you can get started by \"\n          'running your pipeline with the --create_test flag enabled.')\n\n    tests = [\n        yaml_testing.YamlTestCase(\n            pipeline_spec, test_spec, options, known_args.fix_tests)\n        for test_spec in test_specs\n    ]\n    suite = unittest.TestSuite(tests)\n    result = unittest.TextTestRunner().run(suite)\n\n  if known_args.fix_tests or known_args.create_test:\n    update_tests(known_args, pipeline_yaml, pipeline_spec, options, tests)\n\n  if exit:","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/main.py#L165-L201","documentation":"run_tests reads the 'tests' attribute from the pipeline spec (or test suite file) and requires it to be a list of test specifications. If 'tests' exists but is not a list (e.g. a string or mapping), a TypeError is raised explaining the required shape.","triggerScenarios":"Running with --test_suite (or a pipeline spec) whose top-level 'tests:' value is a scalar or dict rather than a YAML list, e.g. `tests: mytest` instead of `tests: [ ... ]`.","commonSituations":"Hand-edited YAML test suites where the list syntax was lost (missing dashes); wrapping a single test object directly under tests instead of a one-element list; YAML indentation mistakes collapsing a list into a string.","solutions":["Format 'tests' as a YAML list: each test specification on its own '- ' entry.","If there is only one test, still wrap it in a one-element list: tests:\n  - name: ...\n    ...","Validate the YAML loads as expected (yaml.safe_load) and that type(spec['tests']) is list before running.","Catch the TypeError in tooling and point the author at the offending file/line in their test suite."],"exampleFix":"# before\ntests:\n  name: my_test\n# after\ntests:\n  - name: my_test\n    pipeline: ...\n    expected: [...]","handlingStrategy":"validation","validationCode":"import yaml\nspec = yaml.safe_load(open(suite_file))\ntests = spec.get('tests', []) if isinstance(spec, dict) else []\nassert isinstance(tests, list), f'tests must be a list, got {type(tests).__name__}'","typeGuard":"def is_valid_test_suite(spec):\n    tests = spec.get('tests', []) if isinstance(spec, dict) else []\n    return isinstance(tests, list) and all(isinstance(t, dict) for t in tests)","tryCatchPattern":"try:\n    apache_beam.yaml.main.run(argv)\nexcept TypeError as e:\n    if 'tests attribute must be a list' in str(e):\n        log.error('Fix tests: block in %s — each spec needs a leading dash', suite_file)\n    raise","preventionTips":["Always author test specs as YAML list items with leading dashes.","Run a yaml.safe_load sanity check on test suite files before submitting.","Use an editor YAML schema/linter to catch list-vs-scalar mistakes."],"tags":["python","apache-beam","yaml","testing","config-format"],"backgroundTag":"config-type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}