-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick skip validation test if models or clouds mismatch #1562
Conversation
1cef38a
to
ecc5bac
Compare
parser.addoption( | ||
"--cloud", action="store", default="aws/us-east-2", help="Juju cloud to use" | ||
) | ||
parser.addoption("--cloud", action="store", help="Juju cloud to use") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stop defaulting the cloud type to 'aws/us-east-2`. This isn't necessary
def __init__(self, request): | ||
self._request = request | ||
def __init__(self, config): | ||
self._config = config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
construct with the pytest config
rather than a request
object
self.requests = requests | ||
self.requests_get = asyncify(requests.get) | ||
self.run = asyncify(self.exec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the existing tools.run
is an async version of the new tools.exec
which does away with the async stuff...
@cached_property | ||
def cloud(self): | ||
if _it := self._config.getoption("--cloud"): | ||
return _it | ||
controller_data, _ = self.exec( | ||
"juju", "show-controller", self.controller_name, "--format", "yaml" | ||
) | ||
controller_infos = yaml.safe_load(controller_data) | ||
controller_info, *_ = controller_infos.values() | ||
return controller_info["details"]["cloud"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the cloud field can be loaded from the existing required controller name argument.
async def run(self, cmd: str, *args: str, stdin=None, _tee=False): | ||
def exec(self, cmd: str, *args: str, stdin=None, _tee=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async subprocess
is actually really hard -- this method actually gets much simpler
tools = Tools(request) | ||
await tools._load() | ||
return tools | ||
yield request.config.test_tools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the old fixture now just has to yield the existing tools from the request.config
. See below in pytest_configure
@pytest.fixture | ||
def system_arch(): | ||
return arch | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def skip_by_arch(request, system_arch): | ||
"""Skip tests on specified arches""" | ||
if request.node.get_closest_marker("skip_arch"): | ||
if system_arch in request.node.get_closest_marker("skip_arch").args[0]: | ||
pytest.skip("skipped on this arch: {}".format(system_arch)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This never would have really worked the way it was intended
def pytest_runtest_setup(item): | ||
"""Called to perform the setup phase for a test item.""" | ||
skip_by_model(item) # skip tests if model marking on test mismatches | ||
skip_by_cloud(item) # skip tests if cloud marking on test mismatches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handles quick skipping of the tagged test by model or cloud
def pytest_configure(config): | ||
config.test_tools = Tools(config) | ||
config.test_tools._load() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Load the tools for the validation tests into the config's global space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, this LGTM and is a welcomed fix to better include/skip bits on non-pytest-running arches and for non-gpu capable models (for stuff like nvidia tests).
Overview
on_model
test markingclouds
test markingDetails
Using the pytest feature
pytest_runtest_setup
, we can use the requiredmodel
keyword from config to quickly skip a test if it doesn't match that model nameTools
object in the test not an async loaded object, it can be constructed and loaded inpytest_configure