diff options
author | Adam Spiers <aspiers@suse.com> | 2019-05-21 20:08:38 +0100 |
---|---|---|
committer | Adam Spiers <aspiers@suse.com> | 2019-05-24 16:22:48 +0100 |
commit | f0edbff6f2d5f1c6dc5c6e0b63eeba3d1d8057bb (patch) | |
tree | f63bacc8fc2f82d57854005bdb4730f5e5702bc9 /test-requirements.txt | |
parent | 2e85453879533af0b4d0e1178797d26f026a9423 (diff) | |
download | nova-f0edbff6f2d5f1c6dc5c6e0b63eeba3d1d8057bb.tar.gz |
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
Diffstat (limited to 'test-requirements.txt')
-rw-r--r-- | test-requirements.txt | 1 |
1 files changed, 1 insertions, 0 deletions
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 |