cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot import name 'Test' from partially initialized module 'databricks_test_helper'

burhanudinera20
New Contributor II

I have done install, with this command ' pip install databricks_test_helper '

next get ImportError messages when i try running this code on cloud databricks ;

from databricks_test_helper import *

expected = set([(s, 'double') for s in ('AP', 'AT', 'PE', 'RH', 'V')])

Test.assertEquals(expected, set(powerPlantDF.dtypes), "Incorrect schema for powerPlantDF")

with message error like this :

ImportError: cannot import name 'Test' from partially initialized module 'databricks_test_helper' (most likely due to a circular import) (/local_disk0/.ephemeral_nfs/envs/pythonEnv-06c00f35-e646-4ea3-8758-203f4b6bb94a/lib/python3.9/site-packages/databricks_test_helper/__init__.py)

What the mistake and what should i do , give me suggest solution please

Thanks

3 REPLIES 3

Anonymous
Not applicable

@Burhanudin Badiuzaman​ :

The error message suggests that there may be a circular import happening within the databricks_test_helper module, which is preventing the Test class from being properly imported.

One possible solution is to import the Test class directly from the databricks_test_helper.test_helper

module, instead of using a wildcard import from the top-level databricks_test_helper module. Here is an example of how to modify your code:

from databricks_test_helper.test_helper import Test
 
expected = set([(s, 'double') for s in ('AP', 'AT', 'PE', 'RH', 'V')])
 
Test.assertEquals(expected, set(powerPlantDF.dtypes), "Incorrect schema for powerPlantDF")

This should allow you to import the Test class without triggering the circular import issue.

Alternatively, you could try updating the databricks_test_helper package to a newer version, as this may have already fixed the circular import issue. You can do this by running pip install --upgrade databricks_test_helper.

I hope this helps! Let me know if you have any further questions.

Thanks ms. suteja for your respons,

I have modified the code and upgraded the databricks_test_hepler package, but I still encounter the following error problem like this attach

Best regard

Anonymous
Not applicable

@Burhanudin Badiuzaman​ :

I am sorry to here that you are still getting errors!

If you're still encountering the error, it's possible that there is still a circular import somewhere in your code or in the databricks_test_helper package. Here are a few things you can try:

  1. Check your code for circular imports: Make sure that none of your modules are importing from each other in a circular way. Circular imports can cause strange errors like this one, so it's important to avoid them.
  2. Upgrade the databricks_test_helper package: Make sure that you have the latest version of the package installed. You can do this by running pip install --upgrade databricks_test_helper
  3. Restart the kernel: Sometimes, restarting the kernel can help resolve issues like this. Try restarting the kernel and running your code again.
  4. Use a different package or approach: If none of the above solutions work, you might consider using a different testing package or approach. There are many testing frameworks available for Python, so you might try one of those instead. Alternatively, you might consider writing your own testing functions instead of using databricks_test_helper

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.