Allow tftest fixtures to run tests in parallel
This commit is contained in:
parent
8df9ef9035
commit
144e841ce4
|
@ -54,7 +54,7 @@ jobs:
|
||||||
- name: Run tests environments
|
- name: Run tests environments
|
||||||
id: test-environments
|
id: test-environments
|
||||||
run: |
|
run: |
|
||||||
pytest -n 4 --dist loadfile -vv tests/examples
|
pytest -n 4 -vv tests/examples
|
||||||
|
|
||||||
tests-examples:
|
tests-examples:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -83,7 +83,7 @@ jobs:
|
||||||
- name: Run tests examples
|
- name: Run tests examples
|
||||||
id: test-examples
|
id: test-examples
|
||||||
run: |
|
run: |
|
||||||
pytest -n 4 --dist loadfile -vv tests/modules/examples
|
pytest -n 4 -vv tests/modules/examples
|
||||||
|
|
||||||
tests-modules:
|
tests-modules:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -112,4 +112,4 @@ jobs:
|
||||||
- name: Run tests modules
|
- name: Run tests modules
|
||||||
id: test-modules
|
id: test-modules
|
||||||
run: |
|
run: |
|
||||||
pytest -n 4 --dist loadgroup -vv --ignore=tests/modules/examples tests/modules
|
pytest -n 4 -vv --ignore=tests/modules/examples tests/modules
|
||||||
|
|
|
@ -15,10 +15,12 @@
|
||||||
"Shared fixtures"
|
"Shared fixtures"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import tftest
|
import tftest
|
||||||
|
|
||||||
|
|
||||||
BASEDIR = os.path.dirname(os.path.dirname(__file__))
|
BASEDIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,10 +30,18 @@ def _plan_runner():
|
||||||
|
|
||||||
def run_plan(fixture_path, targets=None, refresh=True, **tf_vars):
|
def run_plan(fixture_path, targets=None, refresh=True, **tf_vars):
|
||||||
"Runs Terraform plan and returns parsed output."
|
"Runs Terraform plan and returns parsed output."
|
||||||
tf = tftest.TerraformTest(fixture_path, BASEDIR,
|
fixture_parent = os.path.dirname(fixture_path)
|
||||||
os.environ.get('TERRAFORM', 'terraform'))
|
fixture_prefix = os.path.basename(fixture_path) + "_"
|
||||||
tf.setup(upgrade=True)
|
|
||||||
return tf.plan(output=True, refresh=refresh, tf_vars=tf_vars, targets=targets)
|
with tempfile.TemporaryDirectory(prefix=fixture_prefix,
|
||||||
|
dir=fixture_parent) as tmp_path:
|
||||||
|
# copy fixture to a temporary directory so we can execute
|
||||||
|
# multiple tests in parallel
|
||||||
|
shutil.copytree(fixture_path, tmp_path, dirs_exist_ok=True)
|
||||||
|
tf = tftest.TerraformTest(tmp_path, BASEDIR,
|
||||||
|
os.environ.get('TERRAFORM', 'terraform'))
|
||||||
|
tf.setup(upgrade=True)
|
||||||
|
return tf.plan(output=True, refresh=refresh, tf_vars=tf_vars, targets=targets)
|
||||||
|
|
||||||
return run_plan
|
return run_plan
|
||||||
|
|
||||||
|
@ -93,12 +103,20 @@ def apply_runner():
|
||||||
"Returns a function to run Terraform apply on a fixture."
|
"Returns a function to run Terraform apply on a fixture."
|
||||||
|
|
||||||
def run_apply(fixture_path, **tf_vars):
|
def run_apply(fixture_path, **tf_vars):
|
||||||
"Runs Terraform apply and returns parsed output"
|
"Runs Terraform plan and returns parsed output."
|
||||||
tf = tftest.TerraformTest(fixture_path, BASEDIR,
|
fixture_parent = os.path.dirname(fixture_path)
|
||||||
os.environ.get('TERRAFORM', 'terraform'))
|
fixture_prefix = os.path.basename(fixture_path) + "_"
|
||||||
tf.setup(upgrade=True)
|
|
||||||
apply = tf.apply(tf_vars=tf_vars)
|
with tempfile.TemporaryDirectory(prefix=fixture_prefix,
|
||||||
output = tf.output(json_format=True)
|
dir=fixture_parent) as tmp_path:
|
||||||
return apply, output
|
# copy fixture to a temporary directory so we can execute
|
||||||
|
# multiple tests in parallel
|
||||||
|
shutil.copytree(fixture_path, tmp_path, dirs_exist_ok=True)
|
||||||
|
tf = tftest.TerraformTest(tmp_path, BASEDIR,
|
||||||
|
os.environ.get('TERRAFORM', 'terraform'))
|
||||||
|
tf.setup(upgrade=True)
|
||||||
|
apply = tf.apply(tf_vars=tf_vars)
|
||||||
|
output = tf.output(json_format=True)
|
||||||
|
return apply, output
|
||||||
|
|
||||||
return run_apply
|
return run_apply
|
||||||
|
|
|
@ -2,3 +2,4 @@ pytest>=6.2.5
|
||||||
PyYAML>=6.0
|
PyYAML>=6.0
|
||||||
tftest>=1.6.3
|
tftest>=1.6.3
|
||||||
marko>=1.2.0
|
marko>=1.2.0
|
||||||
|
pytest-xdist>=2.5.0
|
||||||
|
|
Loading…
Reference in New Issue