From f0edbff6f2d5f1c6dc5c6e0b63eeba3d1d8057bb Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Tue, 21 May 2019 20:08:38 +0100 Subject: Move patch_exists() to nova.test.TestCase for reuse Several existing tests patch os.path.exists() to return a given value, whilst avoiding interfering with other checks for path existence inside the test virtualenv. Currently they do it by duplicating logic. Furthermore, in the near future, more tests (specifically, some SEV functional tests) will want to do the same selective patching, and similarly will need to avoid impacting existence checks on other files within the test virtualenv, e.g. placement-policy.yaml. TestGuestConfigSysinfoSerialOS already had a nice patch_exists() context manager for selectively patching os.path.exists based on the path parameter, so move this to nova.test.TestCase so that it can be reused to reduce duplication, and add appropriate unit test cases. In order to make patch_exists() generic, the path has to be introduced as an extra parameter alongside the desired return value. Additionally make it usable as a decorator, not just a context manager. This is achievable natively in Python 3 with contextlib, and in Python 2 via contextlib2. Change-Id: Ibe7cb29620f06d31059f2a5f94ca180b8671046e --- test-requirements.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'test-requirements.txt') diff --git a/test-requirements.txt b/test-requirements.txt index 87ecc3eabd..318863b7cc 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,6 +3,7 @@ # process, which may cause wedges in the gate later. hacking>=1.1.0,<1.2.0 # Apache-2.0 +contextlib2>=0.5.5;python_version<'3.0' # PSF License coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.0.1 # MIT fixtures>=3.0.0 # Apache-2.0/BSD -- cgit v1.2.1