giovedì 4 gennaio 2024

Python imports for beginner - import errors

 

you can find the code in

https://github.com/andrea-ferraresi/pythonE2EtestingOfRestAPI

 

 

 Visual Studio Code IDE error - this error doesn't have an impact when you execute the tests




Import "rest_client_initialization_and_actions" could not be resolved Pylance reportMissingImports

 

This error is just an IDE error, namely Visual Studio Code cannot find the custom module (in the same folder as the current file I'm developing). To solve it, as it is said in the quick fixes, it is necessary to add to the python.autoComplete.extraPaths setting the path-to-the-module

 

How to fix it

  • If you are importing a module, make sure it exists in your workspace or in a location that is included in the python.autoComplete.extraPaths setting.

https://code.visualstudio.com/docs/python/editing#_importresolvefailure

 

 Execution error

 


 

 response = rest_client_initialization_and_actions.test_getPetsWhichAre("sold")
E       AttributeError: module 'rest_client_initialization_and_actions' has no attribute 'test_getPetsWhichAre'

 

This error is caused by the fact that the imported module defines a class and some functions inside the class, so to actually reference the imported function, the code needs to reference

module.className.function