Skip to content

Commit 368248b

Browse files
giventocodeRobBagbyPrakash Kudkuli Vishnuomri374quanuw
authored
Release 0.1.35 (#74)
* Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes * Parallel runner implementation (#59) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Update README.md * Parallel runner * Rename helper class * Fix collect results * Rename execute method * Use new execute method * Introduce add_test_fixture() method Co-authored-by: Jesus Aguilar <3589801+giventocode@users.noreply.github.com> Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Fix Py4JJavaError serialization issue (#60) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Update README.md * Fix Py4JJavaError serialization issue * Test Py4JJavaError using mocks * Remove Py4J stuff * Still need to install py4j to run tests Co-authored-by: Jesus Aguilar <3589801+giventocode@users.noreply.github.com> Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Add notebook params and debugger (#68) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Update README.md * Add notebook params and debugger * Add example in README.md * Have more explicit notebook_params error message * Revert "Add example in README.md" This reverts commit 1aac73c. * Add examples for notebook params Co-authored-by: Jesus Aguilar <3589801+giventocode@users.noreply.github.com> Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> Co-authored-by: Neyissa Exilus <68079902+nexilus18@users.noreply.github.com> * upgraded python version * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes * Parallel runner implementation (#59) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Update README.md * Parallel runner * Rename helper class * Fix collect results * Rename execute method * Use new execute method * Introduce add_test_fixture() method Co-authored-by: Jesus Aguilar <3589801+giventocode@users.noreply.github.com> Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Fix Py4JJavaError serialization issue (#60) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Update README.md * Fix Py4JJavaError serialization issue * Test Py4JJavaError using mocks * Remove Py4J stuff * Still need to install py4j to run tests Co-authored-by: Jesus Aguilar <3589801+giventocode@users.noreply.github.com> Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Add notebook params and debugger (#68) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> * Update README.md * Add notebook params and debugger * Add example in README.md * Have more explicit notebook_params error message * Revert "Add example in README.md" This reverts commit 1aac73c. * Add examples for notebook params Co-authored-by: Jesus Aguilar <3589801+giventocode@users.noreply.github.com> Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> Co-authored-by: Neyissa Exilus <68079902+nexilus18@users.noreply.github.com> * upgraded python version * version bump, python 3.7 * added py4j requirement * doc update * doc update Co-authored-by: RobBagby <rob@robbagby.com> Co-authored-by: Prakash Kudkuli Vishnu <prvishnu@microsoft.com> Co-authored-by: Omri Mendels <omri374@users.noreply.github.com> Co-authored-by: quanuw <quanuw@gmail.com> Co-authored-by: Quan Nguyen <qunguyen@microsoft.com> Co-authored-by: Thomas Conté <199027+tomconte@users.noreply.github.com> Co-authored-by: Andrew Francisque <andrew.francisque@gmail.com> Co-authored-by: Neyissa Exilus <68079902+nexilus18@users.noreply.github.com>
1 parent e60be0e commit 368248b

13 files changed

Lines changed: 370 additions & 36 deletions

File tree

.github/workflows/pythonpackage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
max-parallel: 4
1111
matrix:
12-
python-version: [3.5]
12+
python-version: [3.7]
1313

1414
steps:
1515
- uses: actions/checkout@v1
@@ -34,5 +34,5 @@ jobs:
3434
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3535
- name: Test with pytest
3636
run: |
37-
pip install pytest
37+
pip install pytest py4j
3838
pytest

.vscode/example_launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Python: Current File",
6+
"type": "python",
7+
"request": "launch",
8+
"console": "integratedTerminal",
9+
"python": "python3",
10+
"module": "cli.nuttercli",
11+
"args": [
12+
"run",
13+
"<Add test pattern here>",
14+
"--cluster_id",
15+
"<Add cluster_id here>",
16+
"--notebook_params",
17+
"{\"example_key_1\": \"example_value_1\", \"example_key_2\": \"example_value_2\"}"
18+
]
19+
}]
20+
}

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
2-
"python.pythonPath": "/usr/bin/python3",
2+
"python.pythonPath": "/usr/bin/python3",
33
"python.testing.pytestArgs": [
44
"tests"
55
],
66
"python.testing.unittestEnabled": false,
77
"python.testing.nosetestsEnabled": false,
8-
"python.testing.pytestEnabled": true
8+
"python.testing.pytestEnabled": true,
9+
"python.envFile": "${workspaceFolder}/.env"
910
}

README.md

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
* [Cluster Installation](#cluster-installation)
88
* [Nutter Fixture](#nutter-fixture)
99
* [Test Cases](#test-cases)
10-
* [before_all and after_all](#before-all-and-after-all)
10+
* [*before_all* and *after_all*](#before-all-and-after-all)
11+
* [Running test fixtures in parallel](#running-test-fixtures-in-parallel)
1112
- [Nutter CLI](#nutter-cli)
1213
* [Getting Started with the Nutter CLI](#getting-started-with-the-nutter-cli)
13-
* [Listing Test Notebooks](#listing-test-notebooks)
14-
* [Executing Test Notebooks](#executing-test-notebooks)
14+
* [Listing test Notebooks](#listing-test-notebooks)
15+
* [Executing test Notebooks](#executing-test-notebooks)
1516
* [Run single test notebook](#run-single-test-notebook)
1617
* [Run multiple tests notebooks](#run-multiple-tests-notebooks)
1718
* [Parallel Execution](#parallel-execution)
@@ -198,6 +199,64 @@ class TestFixture(NutterFixture):
198199
NutterFixture.__init__(self)
199200
```
200201

202+
### Running test fixtures in parallel
203+
204+
205+
Version 0.1.35 includes a parallel runner class ```NutterFixtureParallelRunner``` that facilitates the execution of test fixtures concurrently. This approach could significantly increase the performance of your testing pipeline.
206+
207+
The following code executes two fixtures, ```CustomerTestFixture``` and ```CountryTestFixture``` in parallel.
208+
209+
```Python
210+
from runtime.runner import NutterFixtureParallelRunner
211+
from runtime.nutterfixture import NutterFixture, tag
212+
class CustomerTestFixture(NutterFixture):
213+
def run_customer_data_is_inserted(self):
214+
dbutils.notebook.run('../data/customer_data_import', 600)
215+
216+
def assertion_customer_data_is_inserted(self):
217+
some_tbl = sqlContext.sql('SELECT COUNT(*) AS total FROM customers')
218+
first_row = some_tbl.first()
219+
assert (first_row[0] == 1)
220+
221+
class CountryTestFixture(NutterFixture):
222+
def run_country_data_is_inserted(self):
223+
dbutils.notebook.run('../data/country_data_import', 600)
224+
225+
def assertion_country_data_is_inserted(self):
226+
some_tbl = sqlContext.sql('SELECT COUNT(*) AS total FROM countries')
227+
first_row = some_tbl.first()
228+
assert (first_row[0] == 1)
229+
230+
parallel_runner = NutterFixtureParallelRunner(num_of_workers=2)
231+
parallel_runner.add_test_fixture(CustomerTestFixture())
232+
parallel_runner.add_test_fixture(CountryTestFixture())
233+
234+
result = parallel_runner.execute()
235+
print(result.to_string())
236+
# Comment out the next line (result.exit(dbutils)) to see the test result report from within the notebook
237+
# result.exit(dbutils)
238+
239+
```
240+
241+
The parallel runner combines the test results of both fixtures in a single result.
242+
243+
``` bash
244+
Notebook: N/A - Lifecycle State: N/A, Result: N/A
245+
Run Page URL: N/A
246+
============================================================
247+
PASSING TESTS
248+
------------------------------------------------------------
249+
country_data_is_inserted (11.446587234000617 seconds)
250+
customer_data_is_inserted (11.53276599000128 seconds)
251+
252+
253+
============================================================
254+
255+
Command took 11.67 seconds -- by foo@bar.com at 12/15/2022, 9:34:24 PM on Foo Cluster
256+
```
257+
258+
259+
201260
## Nutter CLI
202261

203262
The Nutter CLI is a command line interface that allows you to execute and list tests via a Command Prompt.
@@ -230,7 +289,7 @@ $env:DATABRICKS_TOKEN="TOKEN"
230289

231290
__Note:__ For more information about personal access tokens review [Databricks API Authentication](https://docs.azuredatabricks.net/dev-tools/api/latest/authentication.html).
232291

233-
### Listing Test Notebooks
292+
### Listing test notebooks
234293

235294
The following command list all test notebooks in the folder ```/dataload```
236295

@@ -248,16 +307,16 @@ You can list all test notebooks in the folder structure using the ```--recursive
248307
nutter list /dataload --recursive
249308
```
250309

251-
### Executing Test Notebooks
310+
### Executing test notebooks
252311

253312
The ```run``` command schedules the execution of test notebooks and waits for their result.
254313

255314
### Run single test notebook
256315

257-
The following command executes the test notebook ```/dataload/test_sourceLoad``` in the cluster ```0123-12334-tonedabc```.
316+
The following command executes the test notebook ```/dataload/test_sourceLoad``` in the cluster ```0123-12334-tonedabc``` with the notebook_param key-value pairs of ```{"example_key_1": "example_value_1", "example_key_2": "example_value_2"}``` (Please note the escaping of quotes):
258317

259318
```bash
260-
nutter run dataload/test_sourceLoad --cluster_id 0123-12334-tonedabc
319+
nutter run dataload/test_sourceLoad --cluster_id 0123-12334-tonedabc --notebook_params "{\"example_key_1\": \"example_value_1\", \"example_key_2\": \"example_value_2\"}"
261320
```
262321

263322
__Note:__ In Azure Databricks you can get the cluster ID by selecting a cluster name from the Clusters tab and clicking on the JSON view.
@@ -267,10 +326,10 @@ __Note:__ In Azure Databricks you can get the cluster ID by selecting a cluster
267326
The Nutter CLI supports the execution of multiple notebooks via name pattern matching. The Nutter CLI applies the pattern to the name of test notebook **without** the *test_* prefix. The CLI also expects that you omit the prefix when specifying the pattern.
268327

269328

270-
Say the *dataload* folder has the following test notebooks: *test_srcLoad* and *test_srcValidation*. The following command will result in the execution of both tests.
329+
Say the *dataload* folder has the following test notebooks: *test_srcLoad* and *test_srcValidation* with the notebook_param key-value pairs of ```{"example_key_1": "example_value_1", "example_key_2": "example_value_2"}```. The following command will result in the execution of both tests.
271330

272331
```bash
273-
nutter run dataload/src* --cluster_id 0123-12334-tonedabc
332+
nutter run dataload/src* --cluster_id 0123-12334-tonedabc --notebook_params "{\"example_key_1\": \"example_value_1\", \"example_key_2\": \"example_value_2\"}"
274333
```
275334

276335
In addition, if you have tests in a hierarchical folder structure, you can recursively execute all tests by setting the ```--recursive``` flag.
@@ -316,6 +375,10 @@ FLAGS
316375
--max_parallel_tests Sets the level of parallelism for test notebook execution.
317376
--recursive Executes all tests in the hierarchical folder structure.
318377
--poll_wait_time Polling interval duration for notebook status. Default is 5 (5 seconds).
378+
--notebook_params Allows parameters to be passed from the CLI tool to the test notebook. From the
379+
notebook, these parameters can then be accessed by the notebook using
380+
the 'dbutils.widgets.get('key')' syntax.
381+
319382
```
320383

321384
__Note:__ You can also use flags syntax for POSITIONAL ARGUMENTS
@@ -435,6 +498,9 @@ steps:
435498
condition: succeededOrFailed()
436499
```
437500
501+
### Debugging Locally
502+
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.
503+
438504
## Contributing
439505

440506
### Contribution Tips

cli/nuttercli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .reportsman import ReportWriters
1818
from . import reportsman as reports
1919

20-
__version__ = '0.1.34'
20+
__version__ = '0.1.35'
2121

2222
BUILD_NUMBER_ENV_VAR = 'NUTTER_BUILD_NUMBER'
2323

@@ -53,22 +53,22 @@ def __init__(self, debug=False, log_to_file=False, version=False):
5353
def run(self, test_pattern, cluster_id,
5454
timeout=120, junit_report=False,
5555
tags_report=False, max_parallel_tests=1,
56-
recursive=False, poll_wait_time=DEFAULT_POLL_WAIT_TIME):
56+
recursive=False, poll_wait_time=DEFAULT_POLL_WAIT_TIME, notebook_params=None):
5757
try:
58-
logging.debug(""" Running tests. test_pattern: {} cluster_id: {} timeout: {}
58+
logging.debug(""" Running tests. test_pattern: {} cluster_id: {} notebook_params: {} timeout: {}
5959
junit_report: {} max_parallel_tests: {}
6060
tags_report: {} recursive:{} """
6161
.format(test_pattern, cluster_id, timeout,
6262
junit_report, max_parallel_tests,
63-
tags_report, recursive))
63+
tags_report, recursive, notebook_params))
6464

6565
logging.debug("Executing test(s): {}".format(test_pattern))
6666

6767
if self._is_a_test_pattern(test_pattern):
6868
logging.debug('Executing pattern')
6969
results = self._nutter.run_tests(
7070
test_pattern, cluster_id, timeout,
71-
max_parallel_tests, recursive, poll_wait_time)
71+
max_parallel_tests, recursive, poll_wait_time, notebook_params)
7272
self._nutter.events_processor_wait()
7373
self._handle_results(results, junit_report, tags_report)
7474
return

common/api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ def list_tests(self, path, recursive=False):
8888
return tests
8989

9090
def run_test(self, testpath, cluster_id,
91-
timeout=120, pull_wait_time=DEFAULT_POLL_WAIT_TIME):
91+
timeout=120, pull_wait_time=DEFAULT_POLL_WAIT_TIME, notebook_params=None):
9292
self._add_status_event(NutterStatusEvents.TestExecutionRequest, testpath)
9393
test_notebook = TestNotebook.from_path(testpath)
9494
if test_notebook is None:
9595
raise InvalidTestException
9696

9797
result = self.dbclient.execute_notebook(
9898
test_notebook.path, cluster_id,
99-
timeout=timeout, pull_wait_time=pull_wait_time)
99+
timeout=timeout, pull_wait_time=pull_wait_time, notebook_params=notebook_params)
100100

101101
return result
102102

103103
def run_tests(self, pattern, cluster_id,
104104
timeout=120, max_parallel_tests=1, recursive=False,
105-
poll_wait_time=DEFAULT_POLL_WAIT_TIME):
105+
poll_wait_time=DEFAULT_POLL_WAIT_TIME, notebook_params=None):
106106

107107
self._add_status_event(NutterStatusEvents.TestExecutionRequest, pattern)
108108
root, pattern_to_match = self._get_root_and_pattern(pattern)
@@ -119,7 +119,7 @@ def run_tests(self, pattern, cluster_id,
119119
NutterStatusEvents.TestsListingFiltered, len(filtered_notebooks))
120120

121121
return self._schedule_and_run(
122-
filtered_notebooks, cluster_id, max_parallel_tests, timeout, poll_wait_time)
122+
filtered_notebooks, cluster_id, max_parallel_tests, timeout, poll_wait_time, notebook_params)
123123

124124
def events_processor_wait(self):
125125
if self._events_processor is None:
@@ -168,20 +168,20 @@ def _get_root_and_pattern(self, pattern):
168168
return root, valid_pattern
169169

170170
def _schedule_and_run(self, test_notebooks, cluster_id,
171-
max_parallel_tests, timeout, pull_wait_time):
171+
max_parallel_tests, timeout, pull_wait_time, notebook_params=None):
172172
func_scheduler = scheduler.get_scheduler(max_parallel_tests)
173173
for test_notebook in test_notebooks:
174174
self._add_status_event(
175175
NutterStatusEvents.TestScheduling, test_notebook.path)
176176
logging.debug(
177177
'Scheduling execution of: {}'.format(test_notebook.path))
178178
func_scheduler.add_function(self._execute_notebook,
179-
test_notebook.path, cluster_id, timeout, pull_wait_time)
179+
test_notebook.path, cluster_id, timeout, pull_wait_time, notebook_params)
180180
return self._run_and_await(func_scheduler)
181181

182-
def _execute_notebook(self, test_notebook_path, cluster_id, timeout, pull_wait_time):
182+
def _execute_notebook(self, test_notebook_path, cluster_id, timeout, pull_wait_time, notebook_params=None):
183183
result = self.dbclient.execute_notebook(test_notebook_path,
184-
cluster_id, None, timeout, pull_wait_time)
184+
cluster_id, timeout, pull_wait_time, notebook_params)
185185
self._add_status_event(NutterStatusEvents.TestExecuted,
186186
ExecutionResultEventData.from_execution_results(result))
187187
logging.debug('Executed: {}'.format(test_notebook_path))

common/apiclient.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def list_objects(self, path):
5656

5757
return workspace_path_obj
5858

59-
def execute_notebook(self, notebook_path, cluster_id,
60-
notebook_params=None, timeout=120,
61-
pull_wait_time=DEFAULT_POLL_WAIT_TIME):
59+
def execute_notebook(self, notebook_path, cluster_id, timeout=120,
60+
pull_wait_time=DEFAULT_POLL_WAIT_TIME,
61+
notebook_params=None):
6262
if not notebook_path:
6363
raise ValueError("empty path")
6464
if not cluster_id:
@@ -68,7 +68,7 @@ def execute_notebook(self, notebook_path, cluster_id,
6868
"Timeout must be greater than {}".format(self.min_timeout))
6969
if notebook_params is not None:
7070
if not isinstance(notebook_params, dict):
71-
raise ValueError("Parameters must be a dictionary")
71+
raise ValueError("Parameters must be in the form of a dictionary (See #run-single-test-notebook section in README)")
7272
if pull_wait_time <= 1:
7373
pull_wait_time = DEFAULT_POLL_WAIT_TIME
7474

common/testresult.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
Licensed under the MIT license.
44
"""
55

6-
from .pickleserializable import PickleSerializable
7-
import pickle
86
import base64
7+
import pickle
8+
9+
from py4j.protocol import Py4JJavaError
10+
11+
from .pickleserializable import PickleSerializable
12+
913

1014
def get_test_results():
1115
return TestResults()
@@ -30,6 +34,9 @@ def append(self, testresult):
3034
self.total_execution_time = total_execution_time
3135

3236
def serialize(self):
37+
for i in self.results:
38+
if isinstance(i.exception, Py4JJavaError):
39+
i.exception = Exception(str(i.exception))
3340
bin_data = pickle.dumps(self)
3441
return str(base64.encodebytes(bin_data), "utf-8")
3542

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ databricks-api
22
requests
33
fire
44
junit_xml
5+
py4j
56

0 commit comments

Comments
 (0)