Add notebook params and debugger

This commit is contained in:
Andrew Francisque 2021-09-14 15:32:23 -04:00
Родитель 081f9df5d7
Коммит 3ad9da810c
6 изменённых файлов: 44 добавлений и 17 удалений

20
.vscode/example_launch.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"python": "python3",
"module": "cli.nuttercli",
"args": [
"run",
"<Add test pattern here>",
"--cluster_id",
"<Add cluster_id here>",
"--notebook_params",
"{\"example_key_1\": \"example_value_1\", \"example_key_2\": \"example_value_2\"}"
]
}]
}

5
.vscode/settings.json поставляемый
Просмотреть файл

@ -1,9 +1,10 @@
{
"python.pythonPath": "/usr/bin/python3",
"python.pythonPath": "/usr/bin/python3",
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"python.envFile": "${workspaceFolder}/.env"
}

Просмотреть файл

@ -316,6 +316,9 @@ FLAGS
--max_parallel_tests Sets the level of parallelism for test notebook execution.
--recursive Executes all tests in the hierarchical folder structure.
--poll_wait_time Polling interval duration for notebook status. Default is 5 (5 seconds).
--notebook_params Allows parameters to be passed from the CLI tool to the test notebook. From the
notebook, these parameters can then be accessed by the notebook using
the 'dbutils.widgets.get('key')' syntax.
```
__Note:__ You can also use flags syntax for POSITIONAL ARGUMENTS
@ -435,6 +438,9 @@ steps:
condition: succeededOrFailed()
```
### Debugging Locally
If using Visual Studio Code, you can use the `example_launch.json` file provided, editing the variables in the `<>` symbols to match your environment. You should be able to use the debugger to see the test run results, much the same as you would in Azure Devops.
## Contributing
### Contribution Tips

Просмотреть файл

@ -53,14 +53,14 @@ class NutterCLI(object):
def run(self, test_pattern, cluster_id,
timeout=120, junit_report=False,
tags_report=False, max_parallel_tests=1,
recursive=False, poll_wait_time=DEFAULT_POLL_WAIT_TIME):
recursive=False, poll_wait_time=DEFAULT_POLL_WAIT_TIME, notebook_params=None):
try:
logging.debug(""" Running tests. test_pattern: {} cluster_id: {} timeout: {}
logging.debug(""" Running tests. test_pattern: {} cluster_id: {} notebook_params: {} timeout: {}
junit_report: {} max_parallel_tests: {}
tags_report: {} recursive:{} """
.format(test_pattern, cluster_id, timeout,
junit_report, max_parallel_tests,
tags_report, recursive))
tags_report, recursive, notebook_params))
logging.debug("Executing test(s): {}".format(test_pattern))
@ -68,7 +68,7 @@ class NutterCLI(object):
logging.debug('Executing pattern')
results = self._nutter.run_tests(
test_pattern, cluster_id, timeout,
max_parallel_tests, recursive, poll_wait_time)
max_parallel_tests, recursive, poll_wait_time, notebook_params)
self._nutter.events_processor_wait()
self._handle_results(results, junit_report, tags_report)
return

Просмотреть файл

@ -88,7 +88,7 @@ class Nutter(NutterApi):
return tests
def run_test(self, testpath, cluster_id,
timeout=120, pull_wait_time=DEFAULT_POLL_WAIT_TIME):
timeout=120, pull_wait_time=DEFAULT_POLL_WAIT_TIME, notebook_params=None):
self._add_status_event(NutterStatusEvents.TestExecutionRequest, testpath)
test_notebook = TestNotebook.from_path(testpath)
if test_notebook is None:
@ -96,13 +96,13 @@ class Nutter(NutterApi):
result = self.dbclient.execute_notebook(
test_notebook.path, cluster_id,
timeout=timeout, pull_wait_time=pull_wait_time)
timeout=timeout, pull_wait_time=pull_wait_time, notebook_params=notebook_params)
return result
def run_tests(self, pattern, cluster_id,
timeout=120, max_parallel_tests=1, recursive=False,
poll_wait_time=DEFAULT_POLL_WAIT_TIME):
poll_wait_time=DEFAULT_POLL_WAIT_TIME, notebook_params=None):
self._add_status_event(NutterStatusEvents.TestExecutionRequest, pattern)
root, pattern_to_match = self._get_root_and_pattern(pattern)
@ -119,7 +119,7 @@ class Nutter(NutterApi):
NutterStatusEvents.TestsListingFiltered, len(filtered_notebooks))
return self._schedule_and_run(
filtered_notebooks, cluster_id, max_parallel_tests, timeout, poll_wait_time)
filtered_notebooks, cluster_id, max_parallel_tests, timeout, poll_wait_time, notebook_params)
def events_processor_wait(self):
if self._events_processor is None:
@ -168,7 +168,7 @@ class Nutter(NutterApi):
return root, valid_pattern
def _schedule_and_run(self, test_notebooks, cluster_id,
max_parallel_tests, timeout, pull_wait_time):
max_parallel_tests, timeout, pull_wait_time, notebook_params=None):
func_scheduler = scheduler.get_scheduler(max_parallel_tests)
for test_notebook in test_notebooks:
self._add_status_event(
@ -176,12 +176,12 @@ class Nutter(NutterApi):
logging.debug(
'Scheduling execution of: {}'.format(test_notebook.path))
func_scheduler.add_function(self._execute_notebook,
test_notebook.path, cluster_id, timeout, pull_wait_time)
test_notebook.path, cluster_id, timeout, pull_wait_time, notebook_params)
return self._run_and_await(func_scheduler)
def _execute_notebook(self, test_notebook_path, cluster_id, timeout, pull_wait_time):
def _execute_notebook(self, test_notebook_path, cluster_id, timeout, pull_wait_time, notebook_params=None):
result = self.dbclient.execute_notebook(test_notebook_path,
cluster_id, None, timeout, pull_wait_time)
cluster_id, timeout, pull_wait_time, notebook_params)
self._add_status_event(NutterStatusEvents.TestExecuted,
ExecutionResultEventData.from_execution_results(result))
logging.debug('Executed: {}'.format(test_notebook_path))

Просмотреть файл

@ -56,9 +56,9 @@ class DatabricksAPIClient(object):
return workspace_path_obj
def execute_notebook(self, notebook_path, cluster_id,
notebook_params=None, timeout=120,
pull_wait_time=DEFAULT_POLL_WAIT_TIME):
def execute_notebook(self, notebook_path, cluster_id, timeout=120,
pull_wait_time=DEFAULT_POLL_WAIT_TIME,
notebook_params=None):
if not notebook_path:
raise ValueError("empty path")
if not cluster_id: