diff options
author | Phil Dawson <phil.dawson@codethink.co.uk> | 2019-04-18 17:34:35 +0100 |
---|---|---|
committer | Phil Dawson <phil.dawson@codethink.co.uk> | 2019-04-26 10:37:48 +0100 |
commit | 72e09e2807fee4449b6007a87ef9b9c0c77dcad5 (patch) | |
tree | 4ed90b195fa47867bded047eed41384ba1a067a1 | |
parent | a41b50ba81aebae2e32c92ca5a310b293738273d (diff) | |
download | buildstream-72e09e2807fee4449b6007a87ef9b9c0c77dcad5.tar.gz |
testing: make Integration cache fixture available in testing modulephil/move-integration-cache-to-testing
The cli_integration fixture provided in testing.runcli depends on the
integration cache fixture. This was missed when cli_integration was
originally exposed.
-rw-r--r-- | buildstream/testing/__init__.py | 1 | ||||
-rw-r--r-- | buildstream/testing/integration.py | 46 | ||||
-rwxr-xr-x | tests/conftest.py | 53 |
3 files changed, 50 insertions, 50 deletions
diff --git a/buildstream/testing/__init__.py b/buildstream/testing/__init__.py index 62025ded0..0b1c1fd73 100644 --- a/buildstream/testing/__init__.py +++ b/buildstream/testing/__init__.py @@ -24,6 +24,7 @@ from collections import OrderedDict from . import _sourcetests from .repo import Repo from .runcli import cli, cli_integration, cli_remote_execution +from .integration import integration_cache # To make use of these test utilities it is necessary to have pytest # available. However, we don't want to have a hard dependency on diff --git a/buildstream/testing/integration.py b/buildstream/testing/integration.py index e29f480ea..01635de74 100644 --- a/buildstream/testing/integration.py +++ b/buildstream/testing/integration.py @@ -23,6 +23,10 @@ integration tests. """ import os +import shutil +import tempfile + +import pytest # Return a list of files relative to the given directory @@ -49,3 +53,45 @@ def assert_contains(directory, expected): if missing: raise AssertionError("Missing {} expected elements from list: {}" .format(len(missing), missing)) + + +class IntegrationCache: + + def __init__(self, cache): + self.root = os.path.abspath(cache) + os.makedirs(cache, exist_ok=True) + + # Use the same sources every time + self.sources = os.path.join(self.root, 'sources') + + # Create a temp directory for the duration of the test for + # the artifacts directory + try: + self.cachedir = tempfile.mkdtemp(dir=self.root, prefix='cache-') + except OSError as e: + raise AssertionError("Unable to create test directory !") from e + + +@pytest.fixture(scope='session') +def integration_cache(request): + # 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') + + cache = IntegrationCache(cache_dir) + + yield cache + + # Clean up the artifacts after each test session - we only want to + # cache sources between tests + try: + shutil.rmtree(cache.cachedir) + except FileNotFoundError: + pass + try: + shutil.rmtree(os.path.join(cache.root, 'cas')) + except FileNotFoundError: + pass diff --git a/tests/conftest.py b/tests/conftest.py index 9b8ff2414..31b86e301 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,11 +20,12 @@ # Tristan Maat <tristan.maat@codethink.co.uk> # import os -import shutil -import tempfile import pytest from buildstream._platform.platform import Platform + from buildstream.testing import register_repo_kind, sourcetests_collection_hook +from buildstream.testing.integration import integration_cache # pylint: disable=unused-import + from tests.testutils.repo.git import Git from tests.testutils.repo.bzr import Bzr @@ -69,54 +70,6 @@ def pytest_runtest_setup(item): ################################################# -# integration_cache fixture # -################################################# -# -# This is yielded by the `integration_cache` fixture -# -class IntegrationCache(): - - def __init__(self, cache): - self.root = os.path.abspath(cache) - os.makedirs(cache, exist_ok=True) - - # Use the same sources every time - self.sources = os.path.join(self.root, 'sources') - - # Create a temp directory for the duration of the test for - # the artifacts directory - try: - self.cachedir = tempfile.mkdtemp(dir=self.root, prefix='cache-') - except OSError as e: - raise AssertionError("Unable to create test directory !") from e - - -@pytest.fixture(scope='session') -def integration_cache(request): - # 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') - - cache = IntegrationCache(cache_dir) - - yield cache - - # Clean up the artifacts after each test run - we only want to - # cache sources between runs - try: - shutil.rmtree(cache.cachedir) - except FileNotFoundError: - pass - try: - shutil.rmtree(os.path.join(cache.root, 'cas')) - except FileNotFoundError: - pass - - -################################################# # remote_services fixture # ################################################# # |