I am looking for a way to override the node.chef_environment either with a kitchen.yml or a policy file.
The backstory is we have cookbooks written for the old role base instead of policy files. These cookbooks have items in them looking for certain chef_environment and branch code off of them. In lieu of changing the code, I was looking for a way to test them in test kitchen. It appears test kitchen, when using a policy file sets the chef_environment to “local” which is fine, we can code to handle that but were seeing if there was a more elegant way to set it to say “dev” at the kitchen or policy level for testing.
You can set the client.rb to use a specific environment as described here Chef Infra . otherwise the node.environment should be set to the policy_group in test-kitchen environment or policy_group both get set to local.
When I try to configure it with the client_rb I get the following error:
Running handlers: [2025-09-02T19:18:10+00:00] ERROR: Running exception handlers Running handlers complete [2025-09-02T19:18:10+00:00] ERROR: Exception handlers complete Infra Phase failed. 0 resources updated in 00 seconds [2025-09-02T19:18:10+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out [2025-09-02T19:18:10+00:00] FATAL: --------------------------------------------------------------------------------------- [2025-09-02T19:18:10+00:00] FATAL: PLEASE PROVIDE THE CONTENTS OF THE stacktrace.out FILE (above) IF YOU FILE A BUG REPORT [2025-09-02T19:18:10+00:00] FATAL: --------------------------------------------------------------------------------------- [2025-09-02T19:18:10+00:00] FATAL: Chef::PolicyBuilder::Policyfile::UnsupportedFeature: Policyfile does not work with an Environment configured.