integration_tests: introduce skipping of tests by OS#702
Conversation
TheRealFalcon
left a comment
There was a problem hiding this comment.
Overall the idea makes sense and seems like a good way forward.
| return [] | ||
|
|
||
|
|
||
| class IntegrationImage: |
There was a problem hiding this comment.
Do you foresee this class growing or taking on more functionality? If not, I don't think it needs to be a class. The constructor isn't directly invoked, so that leaves us with the classmethod constructor and a helper for building. Would it make more sense as a function returning a namedtuple?
There was a problem hiding this comment.
I think we'll be able to write the mark matching logic more succinctly if this class implements a matches(os, release) (or something broadly along those lines). Roughly:
--- a/tests/integration_tests/clouds.py
+++ b/tests/integration_tests/clouds.py
@@ -75,6 +75,11 @@ class ImageSpecification:
"Image tuple: (%s, %s, %s)", self.image_id, self.os, self.release
)
+ def matches(self, os, release):
+ matches_os = self.os is None or self.os == os
+ matches_release = self.release is None or self.release == release
+ return matches_os and matches_release
+
@classmethod
def from_os_image(cls):
parts = integration_settings.OS_IMAGE.split("::", 2)
diff --git a/tests/integration_tests/conftest.py b/tests/integration_tests/conftest.py
index fc52a8de..b482cfa2 100644
--- a/tests/integration_tests/conftest.py
+++ b/tests/integration_tests/conftest.py
@@ -64,14 +64,7 @@ def pytest_runtest_setup(item):
image = ImageSpecification.from_os_image()
if "only_bionic" in test_marks:
# TODO: implement generic matching logic
-
- # Run Ubuntu tests if we either know this image is Ubuntu, or don't
- # know what it is at all
- run_ubuntu_tests = image.os is None or image.os == "ubuntu"
- # Run bionic tests if we either know this image is bionic, or don't
- # know what it is at all
- run_bionic_tests = image.release is None or image.release == "bionic"
- if not (run_ubuntu_tests and run_bionic_tests):
+ if not image.matches("ubuntu", "bionic"):
pytest.skip("Only runs on Ubuntu bionic")(And even if I didn't think the above: arguably a namedtuple with a function that constructs it is just a class without a namespace to put __init__ in. 😉)
| except (ValueError, IndexError): | ||
| pass | ||
| return _released_image_id | ||
| return image.image_spec |
There was a problem hiding this comment.
Is this supposed to be image_id? I don't see where image_spec comes from.
|
On Tue, Dec 01, 2020 at 02:51:37PM -0800, James Falcon wrote:
@TheRealFalcon commented on this pull request.
> except (ValueError, IndexError):
- pass
- return _released_image_id
+ return image.image_spec
Is this supposed to be `image_id`? I don't see where `image_spec` comes from.
Yep, this is what I get for renaming things right before pushing. :p
|
a8de3ff to
3ef0819
Compare
In order to skip tests based on OS or OS release, we need a way of gathering and storing that information. `IntegrationImage` is a class to contain that information and is now used to deconstruct the more complex OS_IMAGE values we now support.
And mark all current tests that are Ubuntu-only with the `ubuntu` mark.
Proposed Commit Message
Additional Context
See the added "Image Selection" doc section for an overview.
Test Steps
Travis should continue to pass, and it should be observed that tests are skipped on non-Ubuntu releases. This can be seen by using an Ubuntu image but lying about its origin with a full
OS_IMAGEspecification:Checklist: