[Python] how to run test in databricks default python bundle?

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I created a databricks bundle "processing" with databricks bundle init using default python template. I am able to "upload and run" main.py [​IMG]

    result:

    5/22/2025, 2:48:43 PM - Uploading assets to databricks workspace...
    5/22/2025, 2:48:45 PM - Creating execution context on cluster 0508-q3425-jqxbhz37 ...
    5/22/2025, 2:49:00 PM - Running src/processing/main.py ...

    +--------------------+---------------------+-------------+-----------+----------+-----------+
    |tpep_pickup_datetime|tpep_dropoff_datetime|trip_distance|fare_amount|pickup_zip|dropoff_zip|
    +--------------------+---------------------+-------------+-----------+----------+-----------+
    | 2016-02-13 21:47:53| 2016-02-13 21:57:15| 1.4| 8.0| 10103| 10110|
    | 2016-02-13 18:29:09| 2016-02-13 18:37:23| 1.31| 7.5| 10023| 10023|
    | 2016-02-06 19:40:58| 2016-02-06 19:52:32| 1.8| 9.5| 10001| 10018|
    | 2016-02-12 19:06:43| 2016-02-12 19:20:54| 2.3| 11.5| 10044| 10111|
    | 2016-02-23 10:27:56| 2016-02-23 10:58:33| 2.6| 18.5| 10199| 10022|
    +--------------------+---------------------+-------------+-----------+----------+-----------+
    only showing top 5 rows
    5/22/2025, 2:49:17 PM - Done (took 33866ms)


    But how to run the test generated along with main.py main_test.py ? If i "upload and run" it i get

    5/22/2025, 2:53:14 PM - Uploading assets to databricks workspace...
    5/22/2025, 2:53:16 PM - Creating execution context on cluster 0508-q3425-jqxbhz37 ...
    5/22/2025, 2:53:22 PM - Running tests/main_test.py ...

    ---------------------------------------------------------------------------
    ModuleNotFoundError Traceback (most recent call last)
    File <frozen runpy>:286, in run_path(path_name, init_globals, run_name)
    File <frozen runpy>:98, in _run_module_code(code, init_globals, mod_name, mod_spec, pkg_name, script_name)
    File <frozen runpy>:88, in _run_code(code, run_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)
    File /home/moritz/workspace/processing/tests/main_test.py:1
    ----> 1 from processing.main import get_taxis, get_spark
    3 def test_main():
    4 taxis = get_taxis(get_spark())
    main_test.py:1
    ModuleNotFoundError: No module named 'processing'
    5/22/2025, 2:53:26 PM - Done (took 12080ms)


    I did not changed any file. i just setup vs-code databricks connect and databricks cli (authentication) - this is why main.py is executing fine.

    Continue reading...

Compartilhe esta Página