Search code examples
pythonpython-3.xpython-importpython-behave

Full path to import works but file reference doesn't


Looking at this behave tutorial I find that in file features/steps/step_tutorial06.py, if I use from company_model import CompanyModel as is in the example I get Unresolved reference 'company_model' but if I use from features.steps.company_model import CompanyModel it works. Why is this and is there any way around this?

This is in PyCharm.


Solution

  • It's called a Relative import. This is because PyCharm launches python from Project directory and not from the directory you are working in.

    However, to get rid of this long from features.steps.company_model import CompanyModel, you can use from .company_model import CompanyModel since both files are in same directory.