{"record":{"id":"5e3ea6553f1868b1","repo":"apache/beam","slug":"in-file-test-fixing-not-yet-supported-for-templated","errorCode":null,"errorMessage":"In-file test fixing not yet supported for templated pipelines. Please use the --test_suite flag.","messagePattern":"In-file test fixing not yet supported for templated pipelines\\. Please use the --test_suite flag\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/main.py","lineNumber":225,"sourceCode":"\n\ndef update_tests(known_args, pipeline_yaml, pipeline_spec, options, tests):\n  if known_args.test_suite:\n    path = known_args.test_suite\n    if not os.path.exists(path) and known_args.create_test:\n      with open(path, 'w') as fout:\n        fout.write('tests: []')\n  elif known_args.yaml_pipeline_file:\n    path = known_args.yaml_pipeline_file\n  else:\n    raise RuntimeError(\n        'Test fixing only supported for file-backed tests. '\n        'Please use the --test_suite flag.')\n  with open(path) as fin:\n    original_yaml = fin.read()\n  if path == known_args.yaml_pipeline_file and pipeline_yaml.strip(\n  ) != original_yaml.strip():\n    raise RuntimeError(\n        'In-file test fixing not yet supported for templated pipelines. '\n        'Please use the --test_suite flag.')\n  updated_spec = yaml.load(original_yaml, Loader=yaml.SafeLoader) or {}\n\n  if known_args.fix_tests:\n    updated_spec['tests'] = [test.fixed_test() for test in tests]\n\n  if known_args.create_test:\n    if 'tests' not in updated_spec:\n      updated_spec['tests'] = []\n    updated_spec['tests'].append(\n        yaml_testing.create_test(pipeline_spec, options))\n\n  updated_yaml = yaml_utils.patch_yaml(original_yaml, updated_spec)\n  with open(path, 'w') as fout:\n    fout.write(updated_yaml)\n\n","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/main.py#L207-L243","documentation":"Raised by update_tests when the test-suite file is the same as the templated pipeline file and the pipeline YAML on disk differs from the pipeline YAML that was loaded/transformed. In-file test fixing for templated pipelines isn't supported, so Beam refuses to overwrite the file.","triggerScenarios":"Using --yaml_pipeline_file with test fixing (--fix_tests) where pipeline_yaml (possibly normalized/transformed) no longer matches the original file contents verbatim (whitespace-stripped).","commonSituations":"Developers point --yaml_pipeline_file at a templated pipeline and expect fixes to be written in place; template generation rewrote the YAML so the on-disk text diverges from the in-memory pipeline.","solutions":["Split tests into a separate file and pass it via --test_suite instead of --yaml_pipeline_file.","Ensure the on-disk YAML matches the pipeline exactly (avoid pre-transformation) if in-file fixing is intended.","Disable test fixing for templated pipelines and run tests in read-only mode."],"exampleFix":"// before\npython -m apache_beam.yaml.main --yaml_pipeline_file template.yaml --fix_tests\n// after\npython -m apache_beam.yaml.main --test_suite tests.yaml --fix_tests","handlingStrategy":"validation","validationCode":"import yaml\non_disk = open(path).read().strip()\nif path == known_args.yaml_pipeline_file and pipeline_yaml.strip() != on_disk:\n    raise SystemExit('Pipeline file was transformed; use a separate --test_suite file for fixing')","typeGuard":"def safe_for_inplace_fix(path, pipeline_yaml, known_args) -> bool:\n    return path != getattr(known_args, 'yaml_pipeline_file', None) or pipeline_yaml.strip() == open(path).read().strip()","tryCatchPattern":"try:\n    update_tests(...)\nexcept RuntimeError as e:\n    if 'In-file test fixing not yet supported' in str(e):\n        export_tests_to_separate_suite_file(); retry_with_test_suite_flag()\n    else:\n        raise","preventionTips":["Keep tests in a dedicated suite file separate from templated pipelines","Don't pre-normalize YAML passed via --yaml_pipeline_file when fixing tests","Prefer --test_suite for any test mutation workflow"],"tags":["yaml","testing","templates"],"backgroundTag":"unsupported-operation","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"}