My python script with "import pyspark" import failed saying "could not find pyspark module". My code deployment is required to pass through Sonar scan and pyspark module name not listed in our enterprise level artifacts portal and hence the fail.
Can someone please help me understand how can I mock import statement to get out of this issue
thanks in advance.
I have mocked all calls to pyspark API which I am using in my code. But I am not aware of how to mock import statements
Finally, I got this resolved. sys.modules list helped me.
import sys
sys.modules['pyspark'] = dummy_spark_implementation()
I put this statement in my unit test script just before the import statement of my main script(the script to be tested).
this worked for me
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.