Skip to content

Bug: [env] variables from included config files (via include directive) are not passed to test processes #3511

Description

@celinval

Description of the issue

Description: When .cargo/config.toml uses the include directive to pull in another TOML file, any [env] variables defined in that included file are not set when nextest runs tests. The same variables work correctly with cargo test.

Steps to reproduce:

  1. Create .cargo/config.toml:

    include = ["include.toml"]
    
    [env]
    DIRECT = "direct"
  2. Create .cargo/include.toml:

    [env]
    INCLUDE = "include"
  3. Add tests that read both variables at runtime:

    #[test]
    fn env_from_config_toml_direct() {
        // DIRECT is set in [env] inside .cargo/config.toml itself
        assert_eq!(&std::env::var("DIRECT").unwrap(), "direct");
    }
    
    #[test]
    fn env_from_included_toml() {
        // INCLUDE is set in [env] inside .cargo/include.toml, pulled in via
        // `include = ["include.toml"]` at the top of .cargo/config.toml
        assert_eq!(&std::env::var("INCLUDE").unwrap(), "include");
    }
  4. Run cargo test → all tests pass

  5. Run cargo nextest runenv_from_included_toml fails, env_from_config_toml_direct passes

Expected outcome

Both DIRECT and AFF should be set when nextest runs tests, since cargo itself resolves the include directive and both variables are visible to cargo test.

Actual result

cargo nextest run passes DIRECT (from the [env] section in config.toml directly) but does not pass INCLUDE (from the [env] section in the included file):

    Starting 3 tests across 1 binary
        PASS [   0.006s] (1/3) aff2 tests::it_works
        PASS [   0.006s] (2/3) aff2 tests::env_from_config_toml_direct
        FAIL [   0.007s] (3/3) aff2 tests::env_from_included_toml
  stderr ───
    thread 'tests::env_from_included_toml' panicked at src/lib.rs:19:42:
    called `Result::unwrap()` on an `Err` value: NotPresent

cargo test passes all three tests without issue.

Nextest version

cargo-nextest 0.9.140 (a9fef2964 2026-07-05)
release: 0.9.140
commit-hash: a9fef2964e34f64ed4fceeee7c0c3559ce560920
commit-date: 2026-07-05
host: x86_64-unknown-linux-gnu

Additional context

The motivation for using include here is to separate the env variables that are system-dependent and auto-generated (produced by a environment setup step). Keeping them in a separate file allows the generated file to be included without modifying the checked-in config.toml.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions