Skip to content

Register on after_parameters_computation hook to update computed #76

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

Merged
merged 1 commit into from
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backslash/contrib/slash_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
_HAS_TEST_AVOIDED = (int(slash.__version__.split('.')[0]) >= 1)
_HAS_SESSION_INTERRUPT = hasattr(slash.hooks, 'session_interrupt')
_HAS_TEST_DISTRIBUTED = hasattr(slash.hooks, 'test_distributed')
_HAS_PARAMETERS_COMPUTED = hasattr(slash.hooks, 'after_parameters_computation')

def handle_exceptions(func):

Expand Down Expand Up @@ -272,6 +273,11 @@ def test_distributed(self, test_logical_id, worker_session_id): #pylint: disable
if 'report_test_distributed' in self.client.api.info().endpoints:
self.current_test = self.session.report_test_distributed(test_logical_id)

@slash.plugins.register_if(_HAS_PARAMETERS_COMPUTED)
@handle_exceptions
def after_parameters_computation(self): #pylint: disable=unused-argument
self.current_test.update_parameters()

@handle_exceptions
def test_skip(self, reason=None):
self.current_test.mark_skipped(reason=reason)
Expand Down
14 changes: 14 additions & 0 deletions backslash/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from .lazy_query import LazyQuery
from .metadata_holder import MetadataHolder
from .timing_container import TimingContainer
import slash

_UPDATE_PARAMETERS_FUNC = 'update_test_parameters'

class Test(APIObject, MetadataHolder, ErrorContainer, WarningContainer, Commentable, RelatedEntityContainer, TimingContainer):

Expand All @@ -25,6 +27,18 @@ def mark_skipped(self, reason=None):
def report_interrupted(self):
self.client.api.call_function('report_test_interrupted', {'id': self.id})

def update_parameters(self):
variation = getattr(slash.context.test.__slash__, 'variation', None)
if not variation or not _UPDATE_PARAMETERS_FUNC in self.client.api.info().endpoints:
return
updated_param_names = variation.get_computed_parameter_names()
if updated_param_names:
self.client.api.call_function(_UPDATE_PARAMETERS_FUNC,
{
'test_id': self.id,
'parameters': {param_name: variation.values[param_name] for param_name in updated_param_names}
})

def query_errors(self):
"""Queries tests of the current session

Expand Down