Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BlakeWills-BJSS opened this issue Apr 10, 2024 · 1 comment
Labels
enhancement new new issue not yet triaged terraform test

Comments

@BlakeWills-BJSS
Copy link

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

@BlakeWills-BJSS BlakeWills-BJSS added bug new new issue not yet triaged labels Apr 10, 2024
@crw
Copy link
Collaborator

crw commented Apr 10, 2024

Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new new issue not yet triaged terraform test
Projects
None yet
Development

No branches or pull requests

3 participants