summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-01-16 10:42:06 -0500
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-01-16 10:47:21 -0500
commit6286d8209a3db7fcf2b490a55044fa4c2be0c007 (patch)
tree874575658f758a020c74936db2f855ed08c35820
parent4ca37dcd38dc2930bef759a5745c5f158d4b43fe (diff)
downloadbuildstream-6286d8209a3db7fcf2b490a55044fa4c2be0c007.tar.gz
conftest.py: Use different artifact directory for integration tests
To ensure we can run integration tests in parallel, use a tempdir for the artifact cache of each separate integration test run. This makes it possible to run multiple full test runs including integration tests in parallel under detox.
-rwxr-xr-xconftest.py53
-rw-r--r--tests/integration/source-determinism.py4
-rw-r--r--tests/testutils/runcli.py4
3 files changed, 50 insertions, 11 deletions
diff --git a/conftest.py b/conftest.py
index b0b1e280e..6e6e3b08f 100755
--- a/conftest.py
+++ b/conftest.py
@@ -17,15 +17,23 @@
#
# Authors:
# Tristan Maat <tristan.maat@codethink.co.uk>
-
+#
import os
import shutil
-
+import tempfile
import pytest
-
from buildstream._platform.platform import Platform
+#
+# This file is loaded by pytest, we use it to add a custom
+# `--integration` option to our test suite, and to install
+# a session scope fixture.
+#
+
+#################################################
+# Implement pytest option #
+#################################################
def pytest_addoption(parser):
parser.addoption('--integration', action='store_true', default=False,
help='Run integration tests')
@@ -36,26 +44,57 @@ def pytest_runtest_setup(item):
pytest.skip('skipping integration test')
+#################################################
+# integration_cache fixture #
+#################################################
+#
+# This is yielded by the `integration_cache` fixture
+#
+class IntegrationCache():
+
+ def __init__(self, cache):
+ cache = os.path.abspath(cache)
+
+ # Use the same sources every time
+ self.sources = os.path.join(cache, 'sources')
+
+ # Create a temp directory for the duration of the test for
+ # the artifacts directory
+ try:
+ self.artifacts = tempfile.mkdtemp(dir=cache, prefix='artifacts-')
+ except OSError as e:
+ raise AssertionError("Unable to create test directory !") from e
+
+
@pytest.fixture(scope='session')
def integration_cache(request):
- # Set the tempdir to the INTEGRATION_CACHE variable, or the
+ # Set the cache dir to the INTEGRATION_CACHE variable, or the
# default if that is not set.
if 'INTEGRATION_CACHE' in os.environ:
cache_dir = os.environ['INTEGRATION_CACHE']
else:
cache_dir = os.path.abspath('./integration-cache')
- yield cache_dir
+ cache = IntegrationCache(cache_dir)
+
+ yield cache
# Clean up the artifacts after each test run - we only want to
- # cache sources
+ # cache sources between runs
try:
- shutil.rmtree(os.path.join(cache_dir, 'artifacts'))
+ shutil.rmtree(cache.artifacts)
except FileNotFoundError:
pass
+#################################################
+# Automatically reset the platform #
+#################################################
+#
+# This might need some refactor, maybe buildstream
+# needs to cleanup more gracefully and we could remove this.
+#
def clean_platform_cache():
Platform._instance = None
diff --git a/tests/integration/source-determinism.py b/tests/integration/source-determinism.py
index fa12593df..a14f3e5b0 100644
--- a/tests/integration/source-determinism.py
+++ b/tests/integration/source-determinism.py
@@ -94,7 +94,7 @@ def test_deterministic_source_umask(cli, tmpdir, datafiles, kind, integration_ca
return f.read()
finally:
os.umask(old_umask)
- cache_dir = os.path.join(integration_cache, 'artifacts')
+ cache_dir = integration_cache.artifacts
cli.remove_artifact_from_cache(project, element_name,
cache_dir=cache_dir)
@@ -156,7 +156,7 @@ def test_deterministic_source_local(cli, tmpdir, datafiles, integration_cache):
with open(os.path.join(checkoutdir, 'ls-l'), 'r') as f:
return f.read()
finally:
- cache_dir = os.path.join(integration_cache, 'artifacts')
+ cache_dir = integration_cache.artifacts
cli.remove_artifact_from_cache(project, element_name,
cache_dir=cache_dir)
diff --git a/tests/testutils/runcli.py b/tests/testutils/runcli.py
index 0c8e962c2..770f6289a 100644
--- a/tests/testutils/runcli.py
+++ b/tests/testutils/runcli.py
@@ -525,8 +525,8 @@ def cli_integration(tmpdir, integration_cache):
# We want to cache sources for integration tests more permanently,
# to avoid downloading the huge base-sdk repeatedly
fixture.configure({
- 'sourcedir': os.path.join(integration_cache, 'sources'),
- 'artifactdir': os.path.join(integration_cache, 'artifacts')
+ 'sourcedir': integration_cache.sources,
+ 'artifactdir': integration_cache.artifacts
})
return fixture