Skip to content

Terraform test - Subsequent tests should not be skipped when test using expected_failures fails. #34969

@BlakeWills-BJSS

Description

@BlakeWills-BJSS

Terraform Version

Terraform v1.7.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/azurerm v3.98.0

Terraform Configuration Files

main.tf:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "rg" {
  name = "my-test-rg"
  location = "uksouth"
}

tests/skip-tests-1.tftest.hcl

provider "azurerm" {
  features {}
}

run "test_one" {
  command = apply

  expect_failures = [
    azurerm_resource_group.rg
  ]
}

run "test_two" {
  command = apply
}

Debug Output

N/A

Expected Behavior

Both test_one and test_two should execute.

Skipping subsequent tests increases cycle time as it forces multiple test runs to understand all failure cases.

There are cases where multiple related tests may fail for different reasons, and also cases where if test_one fails, it is expected that test_two would also fail, so some sort of toggle to vary the behaviour based on the context would be ideal.

Actual Behavior

test-one runs and fails, then test-two is skipped. I suspect this is deliberate for reasons unknown to me (and not documented), but this behaviour is inconsistent with test failures occurring due to failed assert blocks.

> terraform test
tests/skip-tests-1.tftest.hcl... in progress
  run "test_one"... fail
╷
│ Error: Missing expected failure
│
│   on tests/skip-tests-1.tftest.hcl line 9, in run "test_one":
│    9:     azurerm_resource_group.rg
│
│ The checkable object, azurerm_resource_group.rg, was expected to report an error but did not.
╵
  run "test_two"... skip
tests/skip-tests-1.tftest.hcl... tearing down
tests/skip-tests-1.tftest.hcl... fail

Failure! 0 passed, 1 failed, 1 skipped.

You can work around this by splitting the tests into different files, but this isn't practical with a large number of tests.

Steps to Reproduce

  1. terraform init
  2. terraform test

Additional Context

No response

References

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions