<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to run test of default python asset bundle, how run from terminal in general in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120037#M10072</link>
    <description>&lt;P&gt;As described first i want to get it run remotely using&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dermoritz_0-1747987164650.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/17070i51D53F962804A9CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dermoritz_0-1747987164650.png" alt="dermoritz_0-1747987164650.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How to make this work for the test. Or how to leverage databricks extension correctly that it is uploading all that is needed and sets path correctly.&amp;nbsp;&lt;BR /&gt;Or more generally asked how the test generated by "databricks bundle init" is supposed to run at all? I would also like to run from Terminal, but here i guess certain env variables must be set for databricks-connect to work?&lt;/P&gt;&lt;P&gt;All documentation i found stopped at running the main - what works at least from vs code.&lt;/P&gt;</description>
    <pubDate>Fri, 23 May 2025 08:03:57 GMT</pubDate>
    <dc:creator>dermoritz</dc:creator>
    <dc:date>2025-05-23T08:03:57Z</dc:date>
    <item>
      <title>How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120032#M10070</link>
      <description>&lt;P&gt;I created an asset bundle from default python template. I am able to "upload and run file" main.py from within vs-code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;5/23/2025, 9:01:29 AM - Uploading assets to databricks workspace...
5/23/2025, 9:01:31 AM - Creating execution context on cluster 0508-112319-jqxbhz37 ...
5/23/2025, 9:01:46 AM - 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/23/2025, 9:02:03 AM - Done (took 33813ms)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;But if i do this on "main_test.py" i get:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;5/23/2025, 9:04:48 AM - Uploading assets to databricks workspace...
5/23/2025, 9:04:50 AM - Creating execution context on cluster 0508-112319-jqxbhz37 ...
5/23/2025, 9:04:56 AM - Running tests/main_test.py ...

 

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File &amp;lt;frozen runpy&amp;gt;:286, in run_path(path_name, init_globals, run_name)
File &amp;lt;frozen runpy&amp;gt;:98, in _run_module_code(code, init_globals, mod_name, mod_spec, pkg_name, script_name)
File &amp;lt;frozen runpy&amp;gt;: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
----&amp;gt; 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/23/2025, 9:04:59 AM - Done (took 11291ms)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;How to get the test to run?&lt;/P&gt;&lt;P&gt;And more general how to get things run from within terminal? In terminal i already&lt;BR /&gt;- created a venv installed&lt;BR /&gt;- removing comment from line "&lt;SPAN&gt;databricks-connect&amp;gt;=15.4,&amp;lt;15.5" -&amp;gt; pip install -r requirements-dev.txt&lt;BR /&gt;- &lt;SPAN&gt;export DATABRICKS_CONFIG_PROFILE=adb-xyz&lt;BR /&gt;Yields (for main.py and main_test.py):&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;session.py", line 525, in _from_sdkconfig
    raise Exception("Cluster id or serverless are required but were not specified.")
Exception: Cluster id or serverless are required but were not specified.&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;So how to run test from vs-code and how to run anything from terminal?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 23 May 2025 07:24:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120032#M10070</guid>
      <dc:creator>dermoritz</dc:creator>
      <dc:date>2025-05-23T07:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120033#M10071</link>
      <description>&lt;P&gt;the test script resides in another location (tests subdir) compared to main.py.&lt;/P&gt;&lt;P&gt;So probably what is going on is that the test script cannot find the necessary files (modules).&lt;BR /&gt;So make sure that either the modules are installed or your python path is set.&lt;BR /&gt;it is also important to check where the tests are run: locally or on a databricks cluster.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 07:52:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120033#M10071</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2025-05-23T07:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120037#M10072</link>
      <description>&lt;P&gt;As described first i want to get it run remotely using&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dermoritz_0-1747987164650.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/17070i51D53F962804A9CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dermoritz_0-1747987164650.png" alt="dermoritz_0-1747987164650.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How to make this work for the test. Or how to leverage databricks extension correctly that it is uploading all that is needed and sets path correctly.&amp;nbsp;&lt;BR /&gt;Or more generally asked how the test generated by "databricks bundle init" is supposed to run at all? I would also like to run from Terminal, but here i guess certain env variables must be set for databricks-connect to work?&lt;/P&gt;&lt;P&gt;All documentation i found stopped at running the main - what works at least from vs code.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 08:03:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120037#M10072</guid>
      <dc:creator>dermoritz</dc:creator>
      <dc:date>2025-05-23T08:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120042#M10073</link>
      <description>&lt;P&gt;for databricks-connect to run, you do indeed need to setup the connection(s) to your databricks workspace.&lt;BR /&gt;Personally I do this with a .databrickscfg file in my home folder (using linux). But you can also pass credentials in the sparksession/databrickssession (&lt;A href="https://docs.databricks.com/aws/en/dev-tools/databricks-connect/python" target="_blank"&gt;https://docs.databricks.com/aws/en/dev-tools/databricks-connect/python&lt;/A&gt;, but you are probably aware of this).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The reason why your test script fails but not your main.py is because the test script resides in another location (/tests subdir whereas main.py resides in /src/default_python (or whatever))&lt;BR /&gt;So in your test script, the first thing you do is to import the functions written in main.py (from default_python.main import get_taxis, get_spark).&lt;BR /&gt;It is possible that this works or not, depending on how your python path is set.&lt;BR /&gt;If it does not work, you should add the main.py location to your python path with sys.path.append f.e. (or set it using export PYTHONPATH)).&lt;BR /&gt;This has in fact nothing to do with databricks or dab but the way python works.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 08:21:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120042#M10073</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2025-05-23T08:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120044#M10074</link>
      <description>&lt;P&gt;As i wrote, the setup of connection works - as i am able to run main.py. I have 2 profiles configured (one workspace and one cluster level) - both are "valid".&lt;BR /&gt;Does you 2nd part suggests that there are errors in the default-python template provided by databricks? Because the code i am referring to is completely generated (main and test) - an my question is how to get it working as it is delivered/ generated.&lt;BR /&gt;My assumption is that it should work without changes in code?! is this assumption wrong?&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 08:30:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120044#M10074</guid>
      <dc:creator>dermoritz</dc:creator>
      <dc:date>2025-05-23T08:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120047#M10075</link>
      <description>&lt;P&gt;This assumption is wrong.&lt;BR /&gt;If you look into the directory structure, there is a pytest ini file. This should contain something like:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;pytest&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;testpaths&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; tests&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;pythonpath&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; src&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;pytest ini is executed when you run pytest. so it will append the src dir (where main.py resides).&lt;BR /&gt;But afaik this only works if you run pytest from the directory where pytest ini resides.&lt;BR /&gt;In this case you first have to navigate to the correct directory (cd &amp;lt;project&amp;gt;), and from there run pytest.&lt;BR /&gt;pytest ini will then be executed and it should work.&lt;BR /&gt;there are other ways to make it work f.e. moving main_tests.py to the same dir as main.py etc but i think that first navigating to the correct dir should make it work.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 08:42:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120047#M10075</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2025-05-23T08:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120048#M10076</link>
      <description>&lt;P&gt;I have 2 different problems kind of problems or i see 2 ways to run stuff:&lt;BR /&gt;- using "upload and run" - this works with main, but not with main_test.py. Is main_test.py supposed to work via "upload and run" at all? - for this to work i think i need to upload all needed files not only the file to run?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- using python to run the stuff (here i know to set path and pytest.ini is correctly setup). Here i get for both (either "python main.py" or "pytest tests") the error i showed in first post:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;session.py", line 525, in _from_sdkconfig
    raise Exception("Cluster id or serverless are required but were not specified.")
Exception: Cluster id or serverless are required but were not specified.&lt;/LI-CODE&gt;&lt;P&gt;For this error to fix i guess i have to set an env variable to specify cluster id. within vs-code this is done via gui of Databricks plugin. but how to set cluster id for python / pytest? (as said i was able to set databricks profile via &lt;SPAN&gt;DATABRICKS_CONFIG_PROFILE&lt;/SPAN&gt;)&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 08:55:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120048#M10076</guid>
      <dc:creator>dermoritz</dc:creator>
      <dc:date>2025-05-23T08:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120056#M10077</link>
      <description>&lt;P&gt;- using upload and run your main_test.py will not work.&amp;nbsp; The reason is that databricks will execute the script from its current location, and that will throw an error.&amp;nbsp; You also need the main.py uploaded btw.&lt;BR /&gt;A fix for this is to move the test script to the same directory as the main.py (and also change the import statement to reflect this).&amp;nbsp; But tests typically are not executed like this.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For the second issue: you indeed have to pass a cluster id (or serverless). you can add the cluster id to your profile, that is the easiest way.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 10:15:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120056#M10077</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2025-05-23T10:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120058#M10078</link>
      <description>&lt;P&gt;First let me say thanks for all your effort :-).&lt;/P&gt;&lt;P&gt;can you explain how to pass cluster id or how to add this to the profile?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;is there a way to put this settings specifically the cluster in code - like in .env? because i am about to push this in a repo.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 10:50:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120058#M10078</guid>
      <dc:creator>dermoritz</dc:creator>
      <dc:date>2025-05-23T10:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to run test of default python asset bundle, how run from terminal in general</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120059#M10079</link>
      <description>&lt;P&gt;I figured it out from the docs:&lt;BR /&gt;&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/dev-tools/databricks-connect/cluster-config#cluster" target="_blank"&gt;https://learn.microsoft.com/en-us/azure/databricks/dev-tools/databricks-connect/cluster-config#cluster&lt;/A&gt;&lt;BR /&gt;I don´t put the cluster in code myself because all code runs in Jobs (on job clusters).&amp;nbsp; I only use it for development purposes, so for me it is easiest to put it in the profile.&lt;BR /&gt;But env var is also an option as you can see.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 10:56:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-run-test-of-default-python-asset-bundle-how-run-from/m-p/120059#M10079</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2025-05-23T10:56:21Z</dc:date>
    </item>
  </channel>
</rss>

