{"record":{"id":"de2c0d3d7ac23dce","repo":"astral-sh/ruff","slug":"multiple-sections-with-project-dependencies-in","errorCode":null,"errorMessage":"Multiple sections with `[project]` dependencies in the same file are not allowed. External dependencies must be specified in a single top-level configuration block.","messagePattern":"Multiple sections with `\\[project\\]` dependencies in the same file are not allowed\\. External dependencies must be specified in a single top-level configuration block\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ty_test/src/lib.rs","lineNumber":626,"sourceCode":"    } else {\n        expanded.push(\"lib\");\n        expanded.push(format!(\"python{python_version}\"));\n        expanded.push(\"site-packages\");\n    }\n    expanded.extend(components.skip(1));\n\n    Some(expanded)\n}\n\nfn parse<'s>(\n    short_title: &'s str,\n    source: &'s str,\n) -> anyhow::Result<parser::MarkdownTestSuite<'s, MarkdownTestConfig>> {\n    let mut file_has_dependencies = false;\n    parser::parse::<MarkdownTestConfig>(short_title, source, |config| {\n        if config.dependencies().is_some() {\n            if file_has_dependencies {\n                bail!(\n                    \"Multiple sections with `[project]` dependencies in the same file are not allowed. \\\n                     External dependencies must be specified in a single top-level configuration block.\"\n                );\n            }\n            file_has_dependencies = true;\n        }\n        Ok(())\n    })\n}\n\n#[cfg(test)]\nmod tests {\n    use ruff_python_ast::PythonVersion;\n    use ruff_python_trivia::textwrap::dedent;\n\n    #[test]\n    fn normalizes_site_packages_paths_only_in_diagnostic_locations() {\n        let rendered = \"warning[example]: Invalid value\\n\\","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ty_test/src/lib.rs#L608-L644","documentation":"ty's markdown test parser allows external (`[project]`) dependencies to be declared only once per mdtest file, in a single top-level configuration block. When a second code-block config in the same file also declares dependencies, parsing fails with this error so tests cannot accidentally use ambiguous per-section dependency sets.","triggerScenarios":"Parsing a `.md` test file where two or more `#[config]`/`[project]` configuration blocks each set `dependencies`; raised from `parse` while building the `MarkdownTestSuite`.","commonSituations":"Adding a new test section with its own `[project] dependencies` block to a file that already declares dependencies at the top, or copy-pasting a config block into multiple sections.","solutions":["Keep exactly one top-level configuration block with `[project] dependencies` in the mdtest file and delete the duplicate.","Move dependency-requiring tests that need different packages into separate `.md` files, each with its own single dependency block.","If a section only needs a comment/config for another purpose, strip the `dependencies` key from that block so it no longer counts."],"exampleFix":"<!-- before: two blocks with [project] dependencies in one file -->\n#[config]\n[project]\ndependencies = [\"requests\"]\n...\n#[config]\n[project]\ndependencies = [\"numpy\"]\n\n<!-- after: one block per file -->\n#[config]\n[project]\ndependencies = [\"requests\"]","handlingStrategy":"validation","validationCode":"#!/bin/sh\n# fail if an mdtest file has more than one dependency block\nfor f in \"$@\"; do\n  n=$(grep -c '^\\[project\\]' \"$f\")\n  [ \"$n\" -le 1 ] || { echo \"$f: $n dependency blocks\"; exit 1; }\ndone","typeGuard":null,"tryCatchPattern":"match parser::parse::<MarkdownTestConfig>(short_title, source, on_config) {\n    Err(e) if e.to_string().contains(\"Multiple sections with `[project]` dependencies\") => {\n        eprintln!(\"Fix mdtest file: keep a single top-level [project] dependencies block: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Declare dependencies once at the top of each mdtest file, before any test sections.","Split files when scenarios need different dependency sets.","Add a CI grep/lint check that counts `[project]` blocks per mdtest file."],"tags":["testing","mdtest","configuration","parse-error"],"backgroundTag":"duplicate-config-section","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}