Skip to content

Commit

Permalink
Runnable and Suite configuration support
Browse files Browse the repository at this point in the history
This change allows for the a runnable configuration and the
suite and default configuration to coexist with the correct
behavior.

In short, if the suite has a configuration, it will become
the new default configuration for a runnable, while its own
configuration will not be touched.

Note: there's an opportunity here for changing the data
structure used for the "config" attribute, one that looks
up the value in the "default_config" if it doesn't exist
in the actual "config".  But, given that the size of the
"default_config" will always be very small (given that
it's filtered to contain only the used configuration
by the runner) it seemed an unnecessary optimization
at this time.

Fixes: avocado-framework#5998
Signed-off-by: Cleber Rosa <[email protected]>
  • Loading branch information
clebergnu committed Aug 22, 2024
1 parent 81aac1c commit 57a2566
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
14 changes: 9 additions & 5 deletions avocado/core/nrunner/runnable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import collections
import copy
import json
import logging
import os
Expand Down Expand Up @@ -100,14 +101,13 @@ def __init__(self, kind, uri, *args, config=None, identifier=None, **kwargs):
#: runner has determined that has interes in by setting it in
#: attr:`avocado.core.nrunner.runner.BaseRunner.CONFIGURATION_USED`
self._default_config = self.filter_runnable_config(kind, {})
if config is None:
config = {}
#: This attributes holds configuration from Avocado proper
#: that is passed to runners, as long as a runner declares
#: its interest in using them with
#: attr:`avocado.core.nrunner.runner.BaseRunner.CONFIGURATION_USED`
self._config = {}
if config is None:
config = {}
self.config = self.filter_runnable_config(kind, config)
self._config = config
self.args = args
self.tags = kwargs.pop("tags", None)
self.dependencies = self.read_dependencies(kwargs.pop("dependencies", None))
Expand Down Expand Up @@ -187,7 +187,11 @@ def identifier(self):

@property
def config(self):
return self._config
if not self._config:
return self._default_config
config_with_defaults = copy.copy(self._default_config)
config_with_defaults.update(self._config)
return config_with_defaults

@property
def default_config(self):
Expand Down
4 changes: 3 additions & 1 deletion avocado/core/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def resolutions_to_runnables(resolutions, config):
if resolution.result != ReferenceResolutionResult.SUCCESS:
continue
for runnable in resolution.resolutions:
runnable.config = runnable.filter_runnable_config(runnable.kind, config)
runnable.default_config = runnable.filter_runnable_config(
runnable.kind, config
)
result.append(runnable)
return result

Expand Down
1 change: 1 addition & 0 deletions examples/nrunner/recipes/runnable/noop_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"kind": "noop", "uri": "noop", "config": {"runner.identifier_format": "nothing-op"}}
2 changes: 1 addition & 1 deletion selftests/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"job-api-7": 1,
"nrunner-interface": 70,
"nrunner-requirement": 28,
"unit": 676,
"unit": 677,
"jobs": 11,
"functional-parallel": 307,
"functional-serial": 7,
Expand Down
2 changes: 1 addition & 1 deletion selftests/functional/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_runnables_recipe(self):
==================
asset: 1
exec-test: 3
noop: 2
noop: 3
package: 1
python-unittest: 1
sysinfo: 1"""
Expand Down
11 changes: 11 additions & 0 deletions selftests/unit/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ def test_config_runnable(self):
runnable = suite.tests[0]
self.assertEqual(runnable.config.get("runner.identifier_format"), "NOT FOO")

def test_config_runnable_and_suite(self):
config = {
"resolver.references": [
"examples/nrunner/recipes/runnable/noop_config.json",
],
"runner.identifier_format": "NOT FOO",
}
suite = TestSuite.from_config(config)
runnable = suite.tests[0]
self.assertEqual(runnable.config.get("runner.identifier_format"), "nothing-op")

def tearDown(self):
self.tmpdir.cleanup()

Expand Down

0 comments on commit 57a2566

Please sign in to comment.