Fix random test failures by ignoring .git in copytree (#3949)

This commit is contained in:
Ludovico Magnocavallo
2026-05-08 20:57:40 +02:00
committed by GitHub
parent 98554a9d20
commit 1fd1c9ae98
3 changed files with 18 additions and 11 deletions

View File

@@ -138,6 +138,7 @@ pytest 'tests/modules/project/tftest.yaml::context' --tb=short -s
* **Branching:** Use `username/feature-name`.
* **Commits:** Atomic commits with clear messages.
* **PR Titles:** Avoid semantic commit prefixes. Use Title Case for the first word.
* **Docs:** Do not manually edit the variables/outputs tables in READMEs; use `tfdoc.py`.
## Adding Context Support to a Module

View File

@@ -72,7 +72,12 @@ def _test_terraform_example(plan_validator, example):
directive.kwargs.get('fixtures'))
elif example.type == 'tfvars':
(tmp_path / 'terraform.auto.tfvars').write_text(example.code)
shutil.copytree(example.module, tmp_path, dirs_exist_ok=True)
def ignore_missing(src, names):
return [n for n in names if not (Path(src) / n).exists()]
shutil.copytree(example.module, tmp_path, dirs_exist_ok=True,
ignore=ignore_missing)
tf_var_files = [(tmp_path / 'terraform.auto.tfvars').resolve()]
inventory = []

View File

@@ -42,12 +42,15 @@ def _prepare_root_module(path):
# directories that are automatically read by terraform. Useful
# to avoid surprises if, for example, you have an active fast
# deployment with links to configs)
ignore_patterns = shutil.ignore_patterns('*.auto.tfvars',
'*.auto.tfvars.json',
'[0-9]-*-providers.tf',
'terraform.tfstate*',
'.terraform.lock.hcl',
'terraform.tfvars', '.terraform')
_ignore = shutil.ignore_patterns('*.auto.tfvars', '*.auto.tfvars.json',
'[0-9]-*-providers.tf', 'terraform.tfstate*',
'.terraform.lock.hcl', 'terraform.tfvars',
'.terraform', '.git')
def ignore_patterns(src, names):
ignored = set(_ignore(src, names))
ignored.update([n for n in names if not (Path(src) / n).exists()])
return list(ignored)
with tempfile.TemporaryDirectory(dir=path.parent) as tmp_path:
tmp_path = Path(tmp_path)
@@ -330,10 +333,8 @@ def get_tfvars_for_e2e():
missing_vars = set([f'TFTEST_E2E_{k}' for k in _variables]) - set(
os.environ.keys())
if missing_vars:
raise RuntimeError(
f'Missing environment variables: {missing_vars} required to run E2E tests. '
f'Consult CONTRIBUTING.md to understand how to set them up. '
f'If you want to skip E2E tests add -k "not examples_e2e" to your pytest call'
pytest.skip(
f'Missing environment variables: {missing_vars} required to run E2E tests.'
)
tf_vars = {k: os.environ.get(f'TFTEST_E2E_{k}') for k in _variables}
if tf_vars['region'] == tf_vars['region_secondary']: